random numbers
#10

Actually random number generation is a tricky,
for example in visual basic script (vbs), the random function gives same values every time, when "Randomize" is not added before the code...

Code:
for i=1 to 10
S=int(rnd*10)
msgbox S
next
If you want to test it, make new text file, add the code and save it with extension "vbs" (test.vbs).

For me it give values: 7, 5, 5, 2, 3, 7, 0, 7, 8, 7 each time, same numbers in same order

To make it random add Randomize:

Code:
Randomize
for i=1 to 10
S=int(rnd*10)
msgbox S
next
Same goes for Pascal, i remember coding a Video Poker game and same cards were displayed each time.

Code:
procedure TForm1.Button1Click(Sender: TObject);
var
i: byte;
begin
for i:= 0 to 9 do
memo1.Lines.Append(IntToStr(Random(10)));
end;
Without "Randomize;" it gives: (0,0,8,2,2,6,3,1,3,4) each time the program is executed.
Reply


Messages In This Thread
random numbers - by n00blek - 20.01.2018, 12:05
Re: random numbers - by wallee - 20.01.2018, 12:07
Re: random numbers - by VeryTallMidget - 20.01.2018, 13:02
Re: random numbers - by RogueDrifter - 20.01.2018, 13:44
Re: random numbers - by edyun - 20.01.2018, 14:44
Re: random numbers - by Sew_Sumi - 20.01.2018, 15:06
Re: random numbers - by Redirect Left - 20.01.2018, 16:21
Re: random numbers - by Whillyrez - 20.01.2018, 16:22
Re: random numbers - by n00blek - 20.01.2018, 17:52
Re: random numbers - by VeryTallMidget - 21.01.2018, 18:52
Re: random numbers - by Sew_Sumi - 21.01.2018, 22:56
Re: random numbers - by Crayder - 22.01.2018, 02:49

Forum Jump:


Users browsing this thread: 2 Guest(s)