Math.random not being random

Why is math.random always giving me the number I put in?

math.randomseed(2145107879)
print(math.random(123)) -- 123

math.randomseed(2145107879)
print(math.random(420)) -- 420

math.randomseed(2145107879)
print(math.random(69)) -- 69

math.randomseed(2145107879)
print(math.random(69420)) -- 69420

math.randomseed(2145107879)
print(math.random(100)) -- 100

3 Likes

The issue is that it returns the math.random parameter. So math.random(n) returns n.
For example:

local function setSeed() math.randomseed(2145107879) end

setSeed() print(math.random(100000)) -- 100000

setSeed() print(math.random(123456)) -- 123456

A similar issue with a different seed:

local function setSeed() math.randomseed(1739563286) end

setSeed() print(math.random(100000)) -- 1
setSeed() print(math.random(1000000)) -- 1
setSeed() print(math.random(10000000)) -- 1

When using math.random() you need to hav the minVal it can be and the max value it can be. For Example: math.random(1,10) will give you a random number from the minVal of 1 to the max value of 10.

1 Like

You can use math.random without having 2 arguments.

print(math.random(12)) -- prints a value between 1 and 12

Another issue: somehow I can use math.random to halve my numbers now???

1 Like

I found a few more seeds with the same property for fun:

-284637408, 492875863, 564543304, 1129964900, 1569623060

If any of them are false positives please let me know with an example where math.random(x) == x isn’t true.

I also found the following for dividing numbers by two:

-1784498572, -518695165, 752822958, 964342931, 1762065947

They only work for multiplies of two.

1 Like

Also division by 3, 4, 5, 6, and 69

-- Division by 3
math.randomseed(-1690560216)
print(math.random(2187)) -- 729

-- Division by 4
math.randomseed(-554247864) -- Any: -554247864, 930586453, 1672266041
print(math.random(64)) -- 16

-- Division by 5
math.randomseed(447642815) -- Any: 447642815, 2023003843
print(math.random(500)) -- 100

-- Division by 6
math.randomseed(-922483575) -- Any: -922483575, 1167021562, 1404539171, 1513090956, -563008456
print(math.random(666)) -- 111

-- Division by 69 
math.randomseed(-1752547316) -- Any: -1752547316, 442032435
print(math.random(696969)) -- 10101

There is no such a thing as random … no matter where you look. Computers are seemly random.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.