21.01.2018, 18:52
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...
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:
Same goes for Pascal, i remember coding a Video Poker game and same cards were displayed each time.
Without "Randomize;" it gives: (0,0,8,2,2,6,3,1,3,4) each time the program is executed.
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
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
Code:
procedure TForm1.Button1Click(Sender: TObject); var i: byte; begin for i:= 0 to 9 do memo1.Lines.Append(IntToStr(Random(10))); end;