comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: what's wrong with random
Date: Sun, 22 Dec 2002 20:23:30 GMT
Date: 2002-12-22T20:23:30+00:00	[thread overview]
Message-ID: <6bpN9.265045$pN3.20904@sccrnsc03> (raw)
In-Reply-To: 3e060eb9.4328921@news.freenet.de

> >I think you want the generator to be global to Generate_FileName.
> >Otherwise, it will be reinitialized each time Generate_FileName
>
> When I put
>
>    subtype Int_Slice is Integer range valid_chars'range;
>    package My_Random is new Ada.Numerics.Discrete_Random (Int_Slice);
>
> into the function, nothing changes.
  Making the generator global to the function means making it outside
the function, not moving the instantiation inside the function.
Every time you execute the lines:
>       G      : My_Random.Generator;
>       My_Random.Reset(G);
it resets the random generator.  You don't want it reset, you want it
to continue with the next series of random numbers.  So put those two
lines outside the function.  The first could go right after the
"package My_Random ..." line and the Reset call could go before your
function calling loop.
  The fact that a "delay" changes the behavior suggests that Reset is
setting up a new starting value based on the clock.  Since you get
5 or so duplicate strings when you don't have a "delay", it appears
that your program is generating five strings in the time between clock
ticks.  The time between ticks is dependent on hardware, OS, and
compiler, and the random number package may itself ignore the rightmost
bits, so a "clock tick" could be a long time indeed.



  reply	other threads:[~2002-12-22 20:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-22 18:03 what's wrong with random Jan
2002-12-22 18:38 ` Robert A Duff
2002-12-22 19:17   ` Jan
2002-12-22 20:23     ` tmoran [this message]
2002-12-22 20:56     ` Robert A Duff
2002-12-23 16:39       ` Jan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox