Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is an alternative to to math.randomseed that changes faster than math.randomseed(tick())?

I'm trying to move a textbox to random positions in a frame, and I tried this and no luck.

math.randomseed(os.time())
while wait() do
	wait(0.1)
	script.Parent.Position = UDim2.new(math.random(0.068,0.010),0,math.random(0.020,0.01),0)
	wait(0.1)
end

1 comment

1

what are all these math.random posts.... so consuming... anywho, this doesnt look right in any shape, imagine trying to do "vector3.new(10,10,10)+6" like how would that work.... also use the output, there are tools given for a reason

1 answer

✓ Accepted answer

Okay bro, math.random(a,b) returns an integer value. So fix the code like this:

math.randomseed(os.time())
while wait() do
    wait(0.1)
    script.Parent.Position = UDim2.new(math.random(10,68)/1000,0,math.random(10,20)/1000,0)
    wait(0.1)
end

If you want a more precise method then:

function rand(a,b,precision)
    precision = 10^precision
    local w = 1
    local function che(x,weight)
        return math.floor(x*(10^weight)) == x*(10^weight)
    end
    if che(a,w) and che(b,w) then
        --calculate precision
        return math.random(a*precision,b*precision)/precision
    else
        repeat
            w = w + 1
        until che(a,w) and che(b,w)
        local p = 10^w
        a = a * p
        b = b * p
        --calculate precision
        return math.random(a*precision,b*precision)/(precision*p)
    end
end
print(rand(1,2,3))

With precision before the dot! HOORAY! P.S. Using my rand method is more flexible then hard coding. :winks:

2 comments

0

Thank you for answering my question. I appreciate it.

0

Love your question TOO!

This discussion is preserved as it was. New answers, comments, and votes are closed.