![]() |
|
[Problem] PRNG - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Coding (https://sinister.li/Forum-Coding--71) +--- Thread: [Problem] PRNG (/Thread-Problem-PRNG) |
[Problem] PRNG - noize - 11-29-2013 Code: local random = {}
random.seed = 12345678
function randseed(s)
local seed = s / math.sqrt(0.5)
random.seed = tonumber(string.sub(tostring(seed),2,5) .. string.sub(tostring(seed),-2,-1) .. string.sub(tostring(seed),1,2))
return random.seed
end
function rand(f,c)
random.floor, random.ceil = f, c
random.number = tonumber(string.sub(tostring(random.seed),3,4) .. string.sub(tostring(random.seed),1,3)) or 0 / string.sub(tostring(random.seed),-3,-1) + 0.1
print(random.number) -- here for debugging purposes
while random.number < random.floor or random.number > random.ceil do
math.randomseed(os.time())
if random.number < random.floor then
-- here got to take random.number down a bit
elseif random.number > random.ceil then
-- here got to take random.number up a bit
end
end
return random.number
end
randseed(os.time())
print(rand(40000,59000))This is my code and it all works fine, expect I can't find a way to replace the lines "-- here got to take random.number down/up a bit". If I do something like adding or subtracting 0.1, I would only get numbers very close to either the floor or the ceil. The only way I could think of was using Lua's math.random() function to randomize the numbers to add or deduct, but I don't really want to use other PRNGs in my PRNG. Any idea? |