Board index » delphi » Random number generator

Random number generator

Evesham High School wrote:
> When the generator cycles through the random numbers between
> 1 and 49, it often picks out numbers above 49. Why?

     for num := 1 to 49 do; {<--Error? Should be} BEGIN
        {and added} END;
     until keypressed;

> Ps. How can i stop the generator picking the same number twice without
> setting up different variables for each number generated.

I would add {in pseudocode}
 Var old:integer;
 while num<>old do num:=random
 goto again

"To mangle the Turing Test... If ya can't tell, it doesn't matter."
 -a very wise comment from 'Tangent of the Arc' (moc.1cb@llahd)


Re:Random number generator

JRS:  In article <OeWlgw1#9GA.153@upnetnews03> of Mon, 19 Oct 1998
13:31:14 in comp.lang.pascal.ansi-iso, Evesham High School
<> wrote:
> Help ! Please.
>In the fill Lottery2.pas that is attatched to this message, the scetion of
>code that generates random numbers between 1 and 49 is malfunctioning

>Often it picks numbers that are over 49.

>Can anyone suggest a way to stop this.

>Thanx Michael Carter.   :)

>Ps How do I stop the random number generator picking the same number more
>than once.

>[ A UUEncoded file (lottery.pas) was included here. ]

Please do NOT encode.  It wastes resources and our time.

This is Turbo Pascal, and the correct group is comp.lang.pascal.borland;
where you have earlier posted, and where I have told you where one
"uniqueness" answer is.

Another, inefficient in principle, uniqueness method (which will work)
is to store the "hits" in an array, and scan that to see whether a new
hit is to be accepted.  It would be a better way if drawing, say, two or
three from 1000; you should think why.

Your colours are abominable.

Random(48) should be Random(49) - see manual/help.

I do not see numbers over *48*.

Random()+1 should be Random()+1:2, for neatness.

To c.l.p.a,c.l.p.b, FU c.l.p.b.

John Stockton, Surrey, UK.    Turnpike v4.00    MIME.
  Web <URL:> - TP/BP/&c. FAQqish topics & links.
  Timo's TurboPascal <A HREF="">FAQ</A>.
  <A HREF="">Mini-FAQ</A> of c.l.p.b.

Other Threads