• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua math.random (1.9) almost always returns me 7, this may be a bug?

Mikii

Active Member
Joined
Mar 28, 2013
Messages
197
Reaction score
46
I am running this function at the time of Onstart in Global Events.

PHP:
local  i      =    math.random(1,9)
print(">> NUMBER = " .. i)

almost always (99%) returns me 7, this may be a bug? ( Or I should play in the lottery number 7? rsrsrs)


UPTADE: SEE THIS

Capturar.PNG
PHP:
local  MYVAR         =    math.random(1,9)
  print(">> MY VAR = " ..  MYVAR )
for a = 0, 25 do
   local  TEST        =    math.random(1,9)
   print(">> NUMBER = " .. TEST)
   end
 
Last edited:
Your series are quite low - 26 27rolls? That's likely not going to give flat distribution. Try rolling this on 100k or 1 million rolls or 5 milion or more. Count how many times each number has been rolled. Then we can give okaish prediction about randomness. And even then there is chance for insanely long string of one number. Probability is really, really fickle, especially on short series.
 
@Summ
Do not confuse the variable "my var" with the variable "number" in "for", I just ran this "for" for to test processing. It will be not used variable "number".

Code:
local  MYVAR        =    math.random(1,9)
  print(">> MY VAR = " ..  MYVAR )

MYVAR almost always returns me 7

Look again.
Processed right now.
Capturar.PNG


AND AGAINNN..
Capturar.PNG


@
Gall

I need a number into 1 or 9..



Ho my God 7 Processed right now with new function...

Code:
  local  MYVAR        =    math.floor(math.random(1,100) / 10)
                            print(">> MY VAR = " ..  MYVAR       )
 
Last edited:
http://codepad.org/PCFMak41

from 1000000 iterations, 110945...

This is kind of unnecessary, because one use a 'for' inside a function that already uses an 'is' (mart.ramdom). It's just unnecessarily cumulative processing.


Place this before the first math.random.
Code:
math.randomseed(os.time())
Apparently it did not work well, or maybe I did the wrong way.

Code:
                            math.randomseed(os.time())
                            local  MYVAR        =    math.floor(math.random(1,100) / 10)
                            print(">> MY VAR = " ..  MYVAR)


Returned 7
 
Last edited:
@Summ
@
Gall

I need a number into 1 or 9..



Ho my God 7 Processed right now with new function...

Code:
  local  MYVAR        =    math.floor(math.random(1,100) / 10)
                            print(">> MY VAR = " ..  MYVAR       )
I am talking that, even with lot of those 7 at start you can't be sure that is not randomness after running it like 20 tries. If you could initialize script for ton of times, then we could be sure its not your luck. People win in loteries, get hit by thunder or eaten by sharks even though chances for such events are ridiculously small.
 
I am talking that, even with lot of those 7 at start you can't be sure that is not randomness after running it like 20 tries. If you could initialize script for ton of times, then we could be sure its not your luck. People win in loteries, get hit by thunder or eaten by sharks even though chances for such events are ridiculously small.

Still, always run and the 7 ...
 
Did some research
http://lua-users.org/wiki/MathLibraryTutorial
But beware! The first random number you get is not really 'randomized' (at least in Windows 2K and OS X). To get better pseudo-random number just pop some random number before using them for real:

-- Initialize the pseudo random number generator
math.randomseed( os.time() )
math.random(); math.random(); math.random()
-- done. :)

Looks like it a choice of design.

This is because of similar seeds. You don't really get the same value but
similar values. Try to set the interval to (math.random(0, 32767)) and you
will see the difference.
 
Back
Top