Random function from 17 - 20

hey guys i wanna ask you something. i wanna make a random function from 17 to 20.
but i don't know how to initialized the k value.
i just made it this way
1
2
3
4
5
6
    for(k=17; k<20; k++)
    {
        j = rand() % 20;
        a[j] = a[21];
        a[k]=a[j];
    }

what do you think?
rand() returns a random number, but I believe what you're looking for is:
j = ((rand() % 3 )+ 17);

This will assign j a value of 17-19.
Last edited on
eeerrr i mean 17-19 hehehe ^^v
Corrected.
Make sure that at some point before this happens you've seeded from the system time (which should only happen once in your program).
Topic archived. No new replies allowed.