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

Is there a better way to get a random number between itself and its opposite?

This is what I have for my spread script. "spread" is always going to be positive, and I want the spread to be a random decimal between its opposite and itself.

local NewPos =  mouse + Vector3.new((math.random(spread) - math.random(spread*2)), (math.random(spread) - math.random(spread*2)), (math.random(spread) - math.random(spread*2)))

This is what I had, but it doesn't seem to work too well. Could I get some assistance?

3 comments

0

Could you please give us an example of what you want NewPos to return? I don't really understand.

0

It's bullet spread. It's getting the mouses position, then offsetting it by the a number between -spread and the spread. For example, if spread was -0.25, it could be -0.25, -0.2, -0.1, 0, 0.1... etc, you get the point. Infinite amount of numbers, not listing them all.

0

Why not use the second parameter of math.random?

1 answer

math.random(X,Y) returns a number that is equal to X, equal to Y, or between the two.

2 comments

0

When I tried that it only gave me X or Y nothing between

0

Try putting math.randomseed(tick()) before it.

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