[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Getting randomic integers
- From: "Luciano de Souza" <luchyanus@...>
- Date: Sat, 16 Jan 2010 21:05:04 -0200
It works exactly as I want. I used math.random, but always got the same
numbers, but if I call math.randomseed(os.time()) before, I always got
different numbers. Thank you very much!
----- Original Message -----
From: "Eike Decker" <firstname.lastname@example.org>
To: "Lua list" <email@example.com>
Sent: Saturday, January 16, 2010 8:28 PM
Subject: Re: Getting randomic integers
The randomseed function takes one number that is being used to
initialize the random number generator - otherwise, you'll always get
the same random numbers.
math.randomseed(os.time()) -- initialize based on actual time
for i=1,50 do print(math.random(100)) end -- generate random 50 random
numbers between 1 and 100
Check the manuals for accurate description though:
2010/1/16 Luciano de Souza <firstname.lastname@example.org>:
I could not understand how to get a trully randomic integer. Suppose I
50 randomic integers each time I call a function. Serching in
I found two functions in Math module: math.random and math.randomseed.
The first one is not what I want. Calling it, I got always the same 50
numbers. In Pascal, before using random functions, it's necessary to call
"randomize" which starts the randomic number generator. I don't know if
also necessary in Lua.
But I try to use math.randomseed. The first tesst is:
Despite no errors, I dindn't get anything. So I ask: how to obtain 50
different integers each time I call the randoms functions?
Luciano de Souza