Setting a random number based on a variable

So, I happened to notice that the system has a method where you can set a variable to a random integer :
Spoiler
Control variables > Random _ ~ _
But I can't seem to find a method to set a variable to a random number based on another variable. Does anyone know how to do that?

So, instead of:
x = a random number between 1 and 10
I'm wanting to do:
x = a random number between 1 and y. (Which may or may not be 10 at any given moment)
Script call is more flexible. Use it in Control Variable.

Code:
rand(10)
Will generate 0 ~ 9
Code:
rand(10) + 1
Will generate 1 ~ 10
Code:
rand($game_variables[x]) + 1
Will generate at the minimum value equal to 1 up to 1 + your variable x
So, just to clarify,
Code:
rand($game_variables[x]) + 1
Will create an equivalent range of 1 ~ $game_variable[x]
?
Will create an equivalent range of 1 ~ $game_variable[x]
?
No, it WILL create the maximum value of "min value + (your variable - 1)"
Means if you put the minimum value is 10 and you want it to be 10 ~ 20, your variable value must be 11
i.e
Code:
10 + rand(10)
WILL generate 10 ~ 19
Code:
10 + rand(11)
WILL generate 10 ~ 20
Code:
11 + rand(10)
WILL generate 11 ~ 20
Code:
rand($game_variables[x]) + 1

I'm a bit confused. For a moment, let's go ahead and define the variable. Let's say the variable is equal to 10. Are you saying that
Code:
rand(10)
Will give me a range of 0~9. Am I understanding that much correctly? If I am, then
Code:
rand(10)+1
Will therefore give a range of 1~10, because it will first give me a random number between 0 and 9 (1, 2, 3, 4, 5, 6, 7, 8, or 9) and then add 1.
0+1=1
1+1=2
2+1=3
3+1=4
4+1=5
5+1=6
6+1=7
7+1=8
8+1=9
9+1=10
Therefore making the lowest possible number 1 and the highest number 10, and therefore making the range 1~10. Am I correct in my reasoning?
Am I correct in my reasoning
Yes, that is what Theo was telling you.
And the next step is
Code:
rand($game_variables[x]) + 1
So if you used a variable number 358. The line would read
Code:
rand($game_variables[358]) + 1
And if you put a value of 10 into the variable (358), you would get the same results as
rand(10)+1
You can try to experiment with yourself.
Go to https://repl.it/languages/ruby
Then type
Code:
100.times do
  puts rand(10)
end
Hit run, it will print a random value from 0 ~ 9 in 100 times but never 10.
If you type this instead
Code:
100.times do
puts rand(10) + 1
end
It will print 1 ~ 10 in 100 times but never 0, So...
Am I understanding that much correctly?
Yes, you understand this correctly....
It would be kind of painful to get hit while running @TheoAllen
Thank you.
Thread closed IgnoreMe
Moderator note: Reopened at the request of the OP.
I guess that "Thank You" was a bit premature, because when I actually tried putting the code in, it gave me an error message. Attached is a picture of the error message and what I put into the common event where I'm trying to use it.
You made a typo. You used () instead of []
The correct way would be $game_variables[22] instead of $game_variables(22)
You made a typo
-_- and I do believe this is where a facepalm would be appropriate.

I'll see if it works, and get back to y'all.

Edit:
... AND IT WORKS!!! Thanks!
If your query is fully resolved, please Report your post and ask for the thread to be closed. Mods might not see a post, but they will see a Report.
If your query is fully resolved, please Report your post and ask for the thread to be closed. Mods might not see a post, but they will see a Report.
And yet you as a moderater didn't close the post, even though it appears to be solved and have seen the post
@Oddball That is because quite often the OP comes back after a bit more testing and says they've found a problem. We have learnt not to presume too much. It is only when the post actually says that the thread can be closed that we do. And why exactly did you feel it necessary to post your comment?
@Oddball That is because quite often the OP comes back after a bit more testing and says they've found a problem. We have learnt not to presume too much. It is only when the post actually says that the thread can be closed that we do. And why exactly did you feel it necessary to post your comment?
i don't know. i realized why you didnt close it after posting and am sorry for posting that
@Oddball Okay, apology accepted.

Original thread: https://forums.rpgmakerweb.com/threads/setting-a-random-number-based-on-a-variable.113653/