You asked for 0-3 right? How many numbers are that? Holy ****! It's four!
You really aren't the sharpest knife in the shed are you?
I'll give it a try :
You. Read. Tutorial.
Click this blue underlined word
Again this is for C++, not C.
It is obvious that you are a complete *******; Some are just starting out or simply need help to understand a certain area
#include <stdlib.h> /* needed for rand() function */
#include <time.h> /*needed to call srand() (explained below)*/
int main(void)
{
int r = 0;
/* by calling this function, we seed the random number generator. If we don't seed it, we will get the
same numbers every time we generate random numbers*/
srand(time(0));
/* rand() returns a number from 0 to RAND_MAX (you can output it to see)
by using the % (modulus) operator on a number, the number you will get is from 0 to number-1 */
r = rand() % 4; /* so this returns a number from 0 to 3 */
r = 1 + rand() % 4; /* 1 to 4 and so on*/
return 0;
}
Thank you for posting this code. It works but my only problem is that (in a do-while loop) it generates 0 about 10-15 times then 3 another 10-15 times then 3 another 10-15 times then 2 another 10-15 times then 1 another 10-15 times then 0 again and all over again....
I mean it really isnt random; I need to to generate it 0,3,2,1,3,0,2,0,1,2,3,1,0,2,2
then the next time i run it:
1,3,0,0,2,3,1,1,3,0,2,0,1,3,0
True random numbers
But thank you very much for posting working real working C code and not linking me to a C++ page.