Mail Archives: djgpp/1999/12/10/23:16:38
On 08 Dec 1999 21:10:27 -0800, Nate Eldredge <neldredge AT hmc DOT edu> wrote:
>Mark Simmons <zack97 AT localnet DOT com> writes:
>
>> How do I get a number that will be psuedo random? time(null) % max
>> doesn't work because the numbers need to be read in quick succession and
>> it simply produces a 1,2,3,4,5,6,7,8,9...0,1,2.... etc. pattern.. So,
>> how do I get a number that seems sort of random with a variable max?
>
>Read about `rand' in the documentation. Don't forget to `srand';
>`time(NULL)' makes a good seed.
>
>--
>
>Nate Eldredge
>neldredge AT hmc DOT edu
Try calling time() several times. Each time use the seconds value as
the count for a loop. loop for (;0<seconds--;rand());. This shifts the
sequence along a few
steps, and iterating this loop a few hundred times should randomise
reasonably well.
- Raw text -