Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

PRNG in Math library
Started by prographodeveloper Jun 12 2019 01:23 PM

- - - - -
4 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

prographodeveloper

[GLOBAL: userInfoPane.html]
prographodeveloper
  • Contributor

  • 298 posts
  • Corona SDK

Just out of interest, what PRNG does Lua use?



[TOPIC: post.html]
#2

StarCrunch

[GLOBAL: userInfoPane.html]
StarCrunch
  • Contributor

  • 805 posts
  • Corona SDK

You can see math.random here or in the Corona source. It just calls into the C runtime; a linear congruential generator is pretty typical.

 

There's been some revision of this in 5.4, e.g. see this thread.


  • prographodeveloper likes this

[TOPIC: post.html]
#3

prographodeveloper

[GLOBAL: userInfoPane.html]
prographodeveloper
  • Contributor

  • 298 posts
  • Corona SDK

Interesting, I found a Lua implementation of Mersenne twister, unlike LCG has a very long period.

 

https://github.com/linux-man/randomlua/blob/master/randomlua.lua



[TOPIC: post.html]
#4

davebollinger

[GLOBAL: userInfoPane.html]
davebollinger
  • Corona Geek

  • 1,337 posts
  • Enterprise

if you want a pure-lua mersenne twister, i might suggest this one instead, since it will pass validation - ie, using same seed, will generate an output sequence identical to the reference mt19937ar.out.  (the one you linked offers no way to validate that it's a correct implementation, and a poor/flawed implementation of a good prng = a poor/flawed prng)

 

note that while mt is quite "good", it's ridiculously long period is not a significant factor of its overall "goodness".  that is, if your primary need is a very long period then mt stands out, more than it would if your primary need were "indistinguishable from true randomness", for example.

 

the xoroshiro family are simpler and in many ways "gooder" than mt.



[TOPIC: post.html]
#5

prographodeveloper

[GLOBAL: userInfoPane.html]
prographodeveloper
  • Contributor

  • 298 posts
  • Corona SDK

Thanks, I'll use that.




[topic_controls]
[/topic_controls]