I want to generate a random decimal for a variable, within a certain range. If I use "rand(0.5)" for example, it regards 0.5 as the minimum and will generate anything from that to "0.999999~infinity" or something like that.
But can I set a RANGE of variance? Like, 0.01 to 0.5, for example? If so, how?
A rand call with no arguments generates a number in the [0;1[ range. (Including 0, excluding 1)
In your example you can then use arithmetics to modify the range.
rand * (0.5-0.01) + 0.01
*hugs*
or you can also do
rand(50) * 0.01 + 0.01
For bonus points can you tell us the difference between my and Engr. Adiktuzmiko's code?
Bump.
Please see my EDIT in my previous post.
I tried "$game_variables[11].round" and then showed it in a message box, but it still wasn't rounded... what is the right way to do it?
$game_variables[11] = $game_variables[11].round
if that doesn't work the number might be getting truncated at a prior calculation.
I think you can do .round(2) for example so it cuts off to 2 decimals
EDIT: Oh wait... I think that was for visual basic...
Well, if your only concern is showing the decimals on text, you could always remove parts of the text once you convert that real number into a string
Like you can use
String.index(".")
to find the index of the decimal place, then do
String[0,index+2]
to get a substring up to the decimal + 2 places
so you can do something like
text = $game_variables[number_index].to_s
$game_variables[text_index] = text[0,text.index(".") + 2]
I used two variables coz I assume you need the number value for something so it might be better to leave that variable alone