[Release] nbkRandomSeed - makes better randomseed of lua

Sometimes you may need a truly random number, then this script can make it for you.

you can use to get a seed in other resources

TriggerEvent('RequestRandomSeed',function(Nseed) 
math.randomseed(Nseed)
print(math.random(1,1000))
end)

Client:

debugmode = false 
local lastDebug = 0 
local DebugTime = 1 

local seed = 0

Citizen.CreateThread(function()
    while true do 
        local CRot = GetFinalRenderedCamRot()
        local PBz = GetPedBoneCoords(PlayerPedId(),60309,CRot.z,CRot.z,CRot.z).z
        local seed0 =  ( PBz/1618 * CRot.z/1618 * GetFrameTime()/1.618) * ( PBz/1618 * GetGameTimer() * CRot.z )
        local n , seed1 = math.modf( GetHashKey(seed0)/CRot.z/PBz );
        local seed = math.abs(seed1 * 161803)
        if debugmode then 
            print(seed)
        end 
        TriggerServerEvent('TrulyRandomSeed',seed)
       -- math.random(683,1618)
        Citizen.Wait(math.random(683,1618))
    end 
end)

RegisterNetEvent('TrulyRandomSeed')
AddEventHandler('TrulyRandomSeed', function(SEED)
    seed = SEED
    math.randomseed(seed)
    if debugmode then 
        local nums = {}
        local b = 0 
        local maxi = math.random(683,1618)
       
        for i=1 , maxi do 
            local rand = math.random(1,maxi)
            table.insert(nums,rand)
            if rand > (maxi/2) then 
                b = b+1
            end 
        end 
        
        lastDebug = (100/(maxi/b)) + lastDebug
        print(100/(maxi/b)..'%' .. "Test Average:"..lastDebug/DebugTime.."% with"..DebugTime.." data arrays")
        DebugTime = DebugTime + 1
    end 
end)

AddEventHandler('RequestRandomSeed', function(cb)
    cb(seed)
end)

Server:

local seed = os.time()
math.randomseed(seed)
RegisterServerEvent('TrulyRandomSeed')
AddEventHandler('TrulyRandomSeed', function(SEED)
    seed = SEED
    math.randomseed(seed)
    
    TriggerClientEvent('TrulyRandomSeed',source,seed)
    --[[
    local nums = {}
    local b = 0 
    for i=1 , 100000 do 
        local rand = math.random(1,100)
        table.insert(nums,rand)
        if rand > 50 then 
            b = b+1
        end 
    end 
    
    print(b)]]--
    
end)

AddEventHandler('RequestRandomSeed', function(cb)
    cb(seed)
end)

Github Link

1 Like

I mean… math.random(10000000000,99999999999) and there you have a random number.

1 Like

A seeded PRNG with some arbitrary non-time entropy is still not truly random!

or you can do math.random(math.random(1,100000),math.random(1,1000000)) and just do that like 100 times and you’ll reallllllly have a random number. I think. Haven’t experimented that much with that.