Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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
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 greatneil80 2647 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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:

0
Thank you for answering my question. I appreciate it. Zeta_Dev 34 — 3y
0
Love your question TOO! LinavolicaDev 570 — 3y
Ad

Answer this question