Author Topic: GLB Random Number Algorithm?  (Read 403 times)

Offline Widget101

  • Mc. Print
  • *
  • Posts: 20
    • View Profile
GLB Random Number Algorithm?
« on: 2020-Jun-07 »
Hi there,

Having spent far too long in Elite Dangerous and No Man's Sky I've been playing round with the SEEDRND and RND functions in GLBasic to create a super simple procedural galaxy (well, basically a matrix with repeatable numbers in it to represent stars) and am wondering what algorithm and 'period' GLB uses (if its not a secret!) as its basis??

:)



Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 365
    • View Profile
    • my personal website
Re: GLB Random Number Algorithm?
« Reply #1 on: 2020-Jun-07 »
Hi, generally as You can download GLBasic source (it's >2GB with all stuff) so there are no secrets in any function :-)
GLB is using ISSAC method and 'rand.c' implementation (or whatever it should be called properly) by Bob Jenkins. You can found original code here: https://burtleburtle.net/bob/c/rand.c
It was little modified to work as GLB part, but core is same.


Check my source code editor for GLBasic - link Update: 20.04.2020

Offline Widget101

  • Mc. Print
  • *
  • Posts: 20
    • View Profile
Re: GLB Random Number Algorithm?
« Reply #2 on: 2020-Jun-07 »
Hi, generally as You can download GLBasic source (it's >2GB with all stuff) so there are no secrets in any function :-)
GLB is using ISSAC method and 'rand.c' implementation (or whatever it should be called properly) by Bob Jenkins. You can found original code here: https://burtleburtle.net/bob/c/rand.c
It was little modified to work as GLB part, but core is same.

Thanks for that Dreamerman, that's awesome. Wiki reckons of the ISAAC PRNG that 'Only a few other generators of such high quality and speed exist in usage'.

I was looking into methods for procedural generation and quite a few examples of other systems that I found on the 'tinternet using 'inbuilt' rand functions start developing patterns when graphically representing very large numbers of results, and as such coders were manually implementing the Lehmer or other algorithm. I was wondering whether I'd be getting a similar issue with GLB but it looks really solid, no problems, and I guess that's why! :good:

Quote
Designed for speed and security, ISAAC (Indirection, Shift, Accumulate, Add, and Count) generates 32-bit random numbers. On average, cycles are 2^8295 values long, and are guaranteed to be at least 2^40 values long. The results are uniformly distributed, unbiased, and unpredictable unless you know the seed.

[Note: reading this back before posting makes me sound like I know what I'm talking about!!  :P Just to be clear - I really don't, but do find it fascinating!]

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1645
  • Particle Hawk
    • View Profile
Re: GLB Random Number Algorithm?
« Reply #3 on: 2020-Jun-24 »
You can use rnd() as the seed input too.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)