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);
        {and added} END;
     until keypressed;

Quote:
> 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;
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:

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

--

  Web <URL: http://www.merlyn.demon.co.uk/> - TP/BP/&c. FAQqish topics & links.
  Timo's TurboPascal <A HREF="ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip">FAQ</A>.
  <A HREF="http://www.merlyn.demon.co.uk/clpb-faq.txt">Mini-FAQ</A> of c.l.p.b.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Help with a random number generator...

2. Uniform Random Number Generator

3. Problems concerning random number generator

4. random number generator

5. random number generator

6. Random Number Generator Source Code?

7. Problems with the random number generator in TP7

8. random number generator

9. fpk pascal random numbers generator is strange

10. random number generator ?

11. random number generator for simulation purposes

12. Random Number Generator

 

 
Powered by phpBB® Forum Software