Random vs Pseudo-Random vs Macho Man Random Savage (SOLVED)

math.random( n , m ) produces the same “random” numbers in the same sequence, which is great for testing, but not great if you really want to create a random experience.

math.randomseed( os.time() ) seems to give me random numbers between 0 & 1.

is there any way to throw these in a bag and shake them up to produce actual random numbers while being able to control the range?

i’ll be workin on this all night, feel free to chime in, any help would be appreciated!

UPDATE
This is what I got so far. it works fine as long as you dont need a random number within 1 second because os.time() is measured in seconds.

 math.randomseed(os.time())  -- seed with the current system time
 local num = math.random(1, 10) -- get randomseed within range
 print(num)

First of all, excellent thread name.

You’re on the right track with using math.randomseed(), but the point of that function is to change the output of future math.random() calls instead of using its return value:

math.randomseed(os.time())
print(math.random(1, 100))
print(math.random(1, 100))
print(math.random(1, 100))

I’ve seen socket.gettime() used to generate the initial seed too, not sure if one’s better than the other. There are also a few RNG libraries you might find useful:

1 Like

Haha thanks! More puns to come!

ah! ok cool, so that means I dont have to call math.randomseed(os.time) for each time i call math.random() Excellent!

I will check those out for sure. Its time i learn how to use github anyhow HAHAHA!

If you have a lot of scripts that call on random, I highly recommend dropping math.randomseed(os.time) into your module! one line of code and BAM! Bobs your uncle.