Results 1 to 3 of 3
  1. #1
    mobman11111's Avatar
    Join Date
    Mar 2018
    Gender
    male
    Posts
    2
    Reputation
    10
    Thanks
    0

    LUA math.random algorithm

    Currently, I'm working on a way to predict Nutscript and Clockwork's rolling system so that people can get perfect rolls each go, however one thing I haven't been able to find is the source code for math.random in Lua, if I'm correct the default randomseed is os.time(). If anyone could drop it for me, you'd be doin' me a massive favour.

  2. #2
    mobman11111's Avatar
    Join Date
    Mar 2018
    Gender
    male
    Posts
    2
    Reputation
    10
    Thanks
    0
    I'm also going to ask, what is the default seed Lua uses?

  3. #3
    Gorzoid's Avatar
    Join Date
    Jun 2014
    Gender
    male
    Posts
    227
    Reputation
    10
    Thanks
    990
    https://******.com/LuaDist/lua/blob/...ib.c#L181-L206

    It is dependent on the C++ compiler used.
    The lua manual:
    This function is an interface to the simple pseudo-random generator function rand provided by ANSI C. (No guarantees can be given for its statistical properties.)
    Edit: I have heard that the default seed is 1 but I can't find any official source so it might depend on implementation aswell.

    Edit 2: https://linux.die.net/man/3/rand
    If no seed value is provided, the rand() function is automatically seeded with a value of 1.
    Last edited by Gorzoid; 05-09-2018 at 02:47 PM.
    I am just here to learn, definitely not for hacks... o_O Just learning

Similar Threads

  1. Replies: 2
    Last Post: 04-05-2016, 02:04 PM
  2. [Solved] So I stole some luas from random servs...
    By Sakimoto in forum Garry's Mod Discussions & Help
    Replies: 2
    Last Post: 02-12-2016, 11:55 AM
  3. [Solved] Shoot randomly then kill .lua script??
    By Zekiheil in forum Garry's Mod Discussions & Help
    Replies: 4
    Last Post: 01-07-2016, 01:05 PM
  4. [Solved] Line of code to make my Lua menu change colors randomly
    By ronaldmc123 in forum Garry's Mod Coding & Resources
    Replies: 4
    Last Post: 12-09-2015, 05:35 PM
  5. [Info] How do i make something rotate in a circle using lua, What math.powers would i need?
    By suchisgood in forum Garry's Mod Discussions & Help
    Replies: 7
    Last Post: 05-13-2015, 07:03 AM