#Really randomized numbers
129 messages · Page 1 of 1 (latest)
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.
No unless u wanna rent some CUDA servers
u can create your own pseudo random generator, basically you have to find an algorithm that takes a number, and returns a serial of other numbers between 0 and RAND_MAX (which is the int limit 0x7FFFFFFF)
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
Something like:
Number = 1
Math.random(1,10)
↑↑10x↑↑
If Number is in the Math.random then do something?
*yes I know it's not lua
Just a half code half english explanation of what I meant
What is srand 😭😭😭
well no since here you use Math.random
its for setting a seed, in lua, its ```lua
math.randomseed(0)
Ohhh... Well haven't learned .randomseed yet.
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
because the seed (here the seed is 0) changes
it changes using os.clock()
look
;compile
0.24691184196099
what if i do it again
;compile
0.24691184196099
its the same !
;compile
/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 ?
woops
Maybe randomseed is just for roblox?
;compile
0.24691184196099
So normal lua doesn't have this keyword/command?
nope
Oh ok
;compile
0.24691184196099
it doesnt really changes
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())
;compile
1721493051
0.61925528208814
0.61 ?
;compile
1721493061
0.34762780932669
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...
;compile
0.34762780932669
do you understand @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?
its the number of seconds since epoch
like since the January first of 1970
os.time is not random
basically, randomness is generating non-sence numbers from other numbers
And by that change it makes random numbers
like 1 will give 817926862, 2 will give 65237653, 3 will give 879873111 etc...
yes
but if you know the algorithm
well you can predict random
but you cant predict using lavarand
thats true life random events you can observe
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%?
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
- multiply = 1.86771130
- taking square = 3.48834550015
- multiply again = 3488.34550015
- take the 7 number = 3455001
- nand it = ~(3455001 & 1867711)
you came up with a really different number -1325082
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?
this algorithm is what math.randomseed does
But will generate random numbers , rig.. oh wait yeah no wait
here its my algorithm i did to show you
By os.time I meant
Uhh where it is
I meant the whole algorithm with math.rabdom included
well instead of taking my little plant growth, it will take the actual seconds
This
yes
Yeah sorry I meant the whole script not only the os.time
it will apply an algorithm in the seconds, and then you will have pseudo random
And this is random
this is the actual random
well its not fully random because if i know the seconds, i can predict the result
Yeah, that's true. But it's still better than math.random, ight?
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())
;compile
0.85750753865207
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
Thank you for explaining me that.
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...