lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Why only 90??

On 17.01.2010 16:14, bb wrote:
bb schrieb:
phlnc8 schrieb:
I could not understand how to get a trully randomic integer. Suppose I need
50 randomic integers each time I call a function. Serching in

Assuming you want to print 50 uniform random integers between 0 and 100:

    for i=1,50 do
        print(math.floor(math.random()*100))
    end


---
On Sat, Jan 16, 2010 at 5:12 PM, Luciano de Souza
<luchyanus@predialnet.com.br> wrote:

Hi all,

I could not understand how to get a trully randomic integer. Suppose I need 50 randomic integers each time I call a function. Serching in documentation,
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 it's
also necessary in Lua.

But I try to use math.randomseed. The first tesst is:

print(math.randomseed(100))

print(math.randomseed(0, 100))

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

One correction:
Because of floor() You get numbers between 0 and 99. That might be important for some applications. One can see that in simulating a dice:

print(math.floor(math.random()*5)+1)


Regards BB


One more correction: You get numbers between 0 and 90 only!



--

___________________________________________
Best regards,
Sergey Rozhenko                 mailto:sergroj@mail.ru