#Really randomized numbers

129 messages · Page 1 of 1 (latest)

silent stirrup
#

I've heard that math.random, or even the PC's itself are bad in generating random numbers. Any way to make the chances more "real"/fair?

thin hawk
#

Lavarand, also known as the Wall of Entropy, was a hardware random number generator designed by Silicon Graphics that worked by taking pictures of the patterns made by the floating material in lava lamps, extracting random data from the pictures, and using the result to seed a pseudorandom number generator.

acoustic pumice
bronze sage
brisk sun
#

for example, using the number 0 you need to generate random numbers like
577655601
1248161417
192959563
(this is what the C language generates with seed 0)

#

so you will have to create your own srand and rand function in lua

silent stirrup
#

*yes I know it's not lua

#

Just a half code half english explanation of what I meant

silent stirrup
brisk sun
silent stirrup
#

Ohhh... Well haven't learned .randomseed yet.

brisk sun
#

well randomness works from a seed

#

and its the seed that is random

#
math.randomseed(0)
print(math.random())

this will always be the same number

#

and i can guess it

silent stirrup
#

So wait

#

How can it be random then?

#

If it's always the same

brisk sun
#

it changes using os.clock()

#

look

fleet ferryBOT
#
Program Output
0.24691184196099

brisk sun
#

what if i do it again

fleet ferryBOT
#
Program Output
0.24691184196099

brisk sun
#

its the same !

silent stirrup
#

It's the same

#

Yeah

brisk sun
#

yep

#

now

#
math.randomseed(math.floor(os.clock()))
print(math.random())
fleet ferryBOT
#
Program Output
/opt/wandbox/lua-5.4.3/bin/lua: prog.lua:1: bad argument #1 to 'randomseed' (number has no integer representation)
stack traceback:
[C]: in function 'math.randomseed'
prog.lua:1: in main chunk
[C]: in ?

brisk sun
#

woops

silent stirrup
#

Maybe randomseed is just for roblox?

fleet ferryBOT
#
Program Output
0.24691184196099

silent stirrup
#

So normal lua doesn't have this keyword/command?

brisk sun
silent stirrup
#

Oh ok

fleet ferryBOT
#
Program Output
0.24691184196099

brisk sun
#

its the same

#

because

#

os.clock will be 0

silent stirrup
#

So when os.clock changes

#

The seed changes

#

And the numbers change?

brisk sun
#

os.clock is from where your script started

#

and its mostly 0

#

now check this

#
local t = os.time()
print(t)
math.randomseed(t)
print(math.random())
fleet ferryBOT
#
Program Output
1721493051
0.61925528208814

brisk sun
#

0.61 ?

fleet ferryBOT
#
Program Output
1721493061
0.34762780932669

brisk sun
#

wow its random !

#

because

#

os.time changes every seconds

#

and rand generates a pseudo number from the seed

#

here the seed is 1721493061

#

so the first rand will be 0.34762780932669

#

and we can try it out !

math.randomseed(1721493061)
print(math.random())

it will be 0.3476...

fleet ferryBOT
#
Program Output
0.34762780932669

brisk sun
#

do you understand @silent stirrup ?

silent stirrup
#

It's the same, so the "randomeiness" is in the random os.time?

#

That changes

#

And generates new numbers every time

#

What is os.time?

brisk sun
#

like since the January first of 1970

brisk sun
silent stirrup
#

I mean sorry yeah

#

It changes

brisk sun
#

basically, randomness is generating non-sence numbers from other numbers

silent stirrup
#

And by that change it makes random numbers

brisk sun
#

like 1 will give 817926862, 2 will give 65237653, 3 will give 879873111 etc...

brisk sun
#

but if you know the algorithm

#

well you can predict random

brisk sun
#

thats true life random events you can observe

silent stirrup
# brisk sun well you can predict random

But it's still better than math.random? And other than the fact one can predict it, if there was a 10% chance, would it be really 10%? Or 5%? Or maybe anything between 5 and 15%?

brisk sun
#

here is another example, like imagine you have a plant at your house. Each day you will look how much it groth right ?

so day one you will have 0.0000186771001cm lets say you mesure in millimetters, 0,000186, and you multiply by 10000 so you have 1.86771001

then you take the square of this number (which is 3.48834068145) and then you only take the 7 digits after multiplying by 1000 -> 3406814 and then you nand it by the actual number but with the same number of digits less one so

>>> ~(3406814 & 186771)  
-186771

then you have your random number

#

like the next day for example it will grow 0,000186771130mm which is almost the same
but if we do the same steps

  1. multiply = 1.86771130
  2. taking square = 3.48834550015
  3. multiply again = 3488.34550015
  4. take the 7 number = 3455001
  5. nand it = ~(3455001 & 1867711)

you came up with a really different number -1325082

silent stirrup
#

So os.time is the same?

#

Like a plant that grows (a little) every second, and by a little difference (as a seed) you get a totally different number than the last one?

brisk sun
#

no

#

os.time will just give you the number of seconds

#

which are 1, 2, 3 ...

brisk sun
silent stirrup
#

But will generate random numbers , rig.. oh wait yeah no wait

brisk sun
#

here its my algorithm i did to show you

silent stirrup
#

Uhh where it is

#

I meant the whole algorithm with math.rabdom included

brisk sun
brisk sun
#

yes

silent stirrup
#

Yeah sorry I meant the whole script not only the os.time

brisk sun
#

it will apply an algorithm in the seconds, and then you will have pseudo random

silent stirrup
#

And this is random

brisk sun
silent stirrup
brisk sun
#

like example

#

here its 18h51 in france

#

when it will hit 19h00 (5pm) the os.time will be 1721494800

#
> math.randomseed(1721494800)
> print(math.random())
0.98815881832331
#

so if at 5pm 0m 0s in this specific day i do ;compile, it should give me 0.9881

#
math.randomseed(1721494800)
print(math.random())
fleet ferryBOT
#
Program Output
0.85750753865207

brisk sun
#

well it should give me this number (because its another algorithm than mine)

#

so you can try

#

me i will go back to eat

#

but as you can see its not really random

#

true randoms are lavalamps or my little plant

#

since you dont really know how much it will growth with the exact number

silent stirrup
#

Idk how come, but if I want to know a simple thing like for instance right now - is there a better substitute for math.random, I discover that:

  • something like os.time exists
    I am witnessing some hardcore math going on here, and on an example of a plant and a PC I now know that PC isn't fully random.
#

How do my simple questions (at least that's what I think when I ask them) give complicated anwsers, almost always...