Hi, I do not have a good English, I occupy a translator.
I'm doing a game of dices, but the function Rand () always returns the same values, in C we can occupy srand (time ()) with time() but in PIC C is not the function time ().
I am using the PIC16F877A
In short I am doing this:
srand(7); //Should be srand(time());
randomNum= (rand()%6)+1; //range 1-6
randomNum2= (rand()%6)+1;
setDice(randomNum,1); //setDice function that I did
setDice(randomNum2,2);
I tried to do 1000 forms, but always returns the same order of values
Please help!!!
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Fri Nov 07, 2008 1:49 pm
Quote:
srand(7);
It's not a random number generator. It's a pseudo random
number generator. The srand() function sets the initial state of the
generator. You are using the same seed (7) every time. So you
will get the same sequence every time. To change the sequence
you need to use a different seed.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum