Re: randomizing trouble



In article <7vzXl.1624$u86.17@xxxxxxxxxxxxxxxxxxxx>, Ben <abc@xxxxxxx> wrote:
I have a gawk script that puts random comments into a file. It is run 3
times in a row in quick succession. I found that seeding the random
number generator using gawk did not work because all 3 times it was run
was done within the same second (and it uses the time) - so I decided to

When last I ran into this problem, what I did was to save the last value
returned by rand() to a file, then on the next run, read that in and use
that value as the arg to srand(). Worked well.

Note: You may have to multiply the value by something like 32000 since
rand() returns a small decimal and srand() takes an integer. Anyway,
you get the idea...

.



Relevant Pages

  • Re: rand()
    ... Any other value for seed sets the generator to a random starting ... rand retrieves the pseudorandom numbers that are generated. ... rand before any call to srand generates the same sequence as calling srand ... appear to repeat on successive 'runs' is to use the system time, ...
    (microsoft.public.vc.mfc)
  • Re: randomizing trouble
    ... number generator using gawk did not work because all 3 times it was run ... rand() returns a small decimal and srand() takes an integer. ... Gawk doesn't use randinternally, so it should be producing a larger ...
    (comp.lang.awk)
  • Re: Floating point load-store behaviour.
    ... This should be "int main". ... calling srand(), you're interfering with the generator. ... You should call srand() exactly once, ...
    (comp.lang.c)
  • Re: randomizing trouble
    ... Aharon Robbins wrote: ... randreturns a small decimal and srand() takes an integer. ... Gawk doesn't use rand() internally, so it should be producing a larger ... Note that "man gawk" is somewhat terse about what sort of values should ...
    (comp.lang.awk)
  • Re: Way for computing random primes in standard C.
    ... think there is nothing to stop rand() being a very high quality generator. ... passing that value back to srand(). ... BSD randomman page's discussion of the issue. ...
    (comp.lang.c)