I want a random number that has a greater absolute value than 10 and smaller than 30 how would I go about doing that? (Ive tried using math.clamp, but I get 0 for some results)
Here is an example of what I tried:
local controlPointPosition = mP + tempPoint.RightVector * math.clamp(math.random(-1, 1) * 1000, -controlDistance/2, controlDistance/2)
I don’t understand what you are trying to do.
Do you mean math.random(10, 30)? Or do you want it to be something like min + ((max - min) * math.random())?
return a random number that have a minimum absolute value of 30 to a maximum absolute value of 50
So it can be anything inbetween the min and max, but t cant be outside of the 4
Maximum1 ---------- Minimum1 0 Minimum2 ---------- Maximum2
The -------- is the number range it can return. Does this help?
Hi! It looks like you’re trying to generate a random number. Let me help you with that:
What you’re looking for is something like this:
math.random(10,30)
which will return a value between 10 and 30.
Simple as that!
To assign this value to a variable so you can use it in your code, you can do this:
local randomNumber = math.random(10,30)
Here’s some documentation from Roblox on the matter:
Have fun and good luck!
No I need a random number between -50 to -30 and 30 to 50
Ah, thanks for the clarification!
You can use any integer in the math.random() function, which means negative values as well.
Let’s try something like this:
local randomValueOne = math.random(-30,-50)
local randomValueTwo = math.random(30,50)
This will return two values, one negative and one positive.
Let me know if you have any further questions!
Is there a simple way I can make it pick those two randomly though?
I’m not quite sure what you mean. The math.random() function is returning a random number between the values provided. In this case both -30,-50 and 30,50 respectively.
Could you please elaborate on your request,
Thanks!
Yes, is there a simple way that I can pick one of those two variables randomly each time I call for it?
Got it! Let’s take a look here:
If you’d like to have a function return both of those values, you can do something like this:
function generateNumbers()
local randomValueOne = math.random(-30,-50)
local randomValueTwo = math.random(30,50)
return randomValueOne,randomValueTwo
end
Let me know if you have any further questions
edit: I removed two variables as they aren’t being used, and I placed them there by force of habit
I say you do random for 30 and 50 then make it negative if another random value of [0, 1) is less than .5
But I want to randomly pick only one of those two variables not give both.
If I understand you correctly, it seems like you’re trying to randomly generate two sets of numbers. One negative, and one positive. You’d also like to randomly pick one of those two numbers once generated.
Is this correct?
Yes this is correct like from above Maximum1 ---------- Minimum1 0 Minimum2 ---------- Maximum2 it returns one point random on the two lines.
local randomNumber
if math.random() > 0.5 then
randomNumber = math.random(-30,-50)
else
randomNumber = math.random(30,50)
end
Is this the best way to do this or is there a more “Mathy” way that could be done?
I think this is the best way to do it. I don’t know about any math functions that could achieve the same thing.