Random number generator
Author Message
Random number generator

Quote:

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

{snippet}
repeat
gotoxy(x,10);
for num := 1 to 49 do; {<--Error? Should be} BEGIN
textcolor(blue);
textbackground(white);
write(random(num));
delay(50);
until keypressed;

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

Var old:integer;
again:
while num<>old do num:=random
old:=num
goto again

--
"To mangle the Turing Test... If ya can't tell, it doesn't matter."

Wed, 18 Jun 1902 08:00:00 GMT
Random number generator

13:31:14 in comp.lang.Pascal.ansi-iso, Evesham High School
Quote:

>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
>slightly.

>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

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.

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.

--

Web <URL: http://www.merlyn.demon.co.uk/> - TP/BP/&c. FAQqish topics & links.