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

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

Asked by
gitrog 326 Moderation Voter
6 years ago
Edited 6 years ago

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?

0
Could you please give us an example of what you want NewPos to return? I don't really understand. hiimgoodpack 2009 — 6y
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. gitrog 326 — 6y
0
Why not use the second parameter of math.random? hiimgoodpack 2009 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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

0
When I tried that it only gave me X or Y nothing between gitrog 326 — 6y
0
Try putting math.randomseed(tick()) before it. Thundermaker300 554 — 6y
Ad

Answer this question