I was playing around with the lua interpretor and made this little program that generates two numbers and compares them. The program runs until the numbers match. The first number is randomly generated using math.random(), and is set to 1, and 100000. The second value that is generated to compare is between 1 and 100. It also keeps track of how many times the program loops. The program works as intended, but something strange happens when I run it.
The values that come up are always either 1, 31, 62, or 92. I've run the program many times, but it keeps generating these numbers. I have some understanding of how random numbers are generated, but this just seems weird. I'll paste the code in below. If someone can explain what's going on here, I would appreciate it greatly. Thanks!
counter=0;
a=0;
b=1;
while(a~=b)do
a=math.random(1,1000000);
b=math.random(1,100);
counter=counter+1;
if(a==b)then
print(a..", "..b..", and it took "..counter.." times")
end
end
Aucun commentaire:
Enregistrer un commentaire