Setting a random number based on a variable

Stupidbro

Veteran
Veteran
Joined
Jul 8, 2019
Messages
87
Reaction score
8
First Language
English
Primarily Uses
RMVXA
So, I happened to notice that the system has a method where you can set a variable to a random integer :
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)
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,599
Reaction score
6,552
First Language
Indonesian
Primarily Uses
RMVXA
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
 

Stupidbro

Veteran
Veteran
Joined
Jul 8, 2019
Messages
87
Reaction score
8
First Language
English
Primarily Uses
RMVXA
So, just to clarify,
Code:
rand($game_variables[x]) + 1
Will create an equivalent range of 1 ~ $game_variable[x]
?
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,599
Reaction score
6,552
First Language
Indonesian
Primarily Uses
RMVXA
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
 

Stupidbro

Veteran
Veteran
Joined
Jul 8, 2019
Messages
87
Reaction score
8
First Language
English
Primarily Uses
RMVXA
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?
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,674
Reaction score
566
First Language
English
Primarily Uses
RMVXA
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
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,599
Reaction score
6,552
First Language
Indonesian
Primarily Uses
RMVXA
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....
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
535
First Language
English
Primarily Uses
N/A
It would be kind of painful to get hit while running @TheoAllen
 

Ms Littlefish

Dangerously Caffeinated
Global Mod
Joined
Jan 15, 2014
Messages
6,417
Reaction score
8,104
First Language
English
Primarily Uses
RMMV

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,713
First Language
English
Primarily Uses
RMVXA
[mod]Reopened at the request of the OP.[/mod]
 

Stupidbro

Veteran
Veteran
Joined
Jul 8, 2019
Messages
87
Reaction score
8
First Language
English
Primarily Uses
RMVXA
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.
 

Attachments

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,599
Reaction score
6,552
First Language
Indonesian
Primarily Uses
RMVXA
You made a typo. You used () instead of []
The correct way would be $game_variables[22] instead of $game_variables(22)
 

Stupidbro

Veteran
Veteran
Joined
Jul 8, 2019
Messages
87
Reaction score
8
First Language
English
Primarily Uses
RMVXA
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!
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,713
First Language
English
Primarily Uses
RMVXA
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.
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
535
First Language
English
Primarily Uses
N/A
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
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,713
First Language
English
Primarily Uses
RMVXA
@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

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
535
First Language
English
Primarily Uses
N/A
@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
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Latest Threads

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,454
Members
137,821
Latest member
Capterson
Top