Help me with very simple line of script RPGMXP

Hi'm I'm currently developing a script,and i'm a total noob on this, but i came to a point where i just don't know what i'm doing wrong, and in theory it's very simple.

Lets say I need that the variable X gets a random number between 11 and 14 (including both ends)

how do i do that?
i tried x = rand(11..14) and it says it "can't convert Range into Integrer"
how should I write it then? ._.
have you tried x = rand(3) + 11?

I never did any scripting of any kind, nor did I ever use XP, so take my idea with a grain of salt.
Hi'm I'm currently developing a script,and i'm a total noob on this, but i came to a point where i just don't know what i'm doing wrong, and in theory it's very simple.

Lets say I need that the variable X gets a random number between 11 and 14 (including both ends)

how do i do that?
i tried x = rand(11..14) and it says it "can't convert Range into Integrer"
how should I write it then? ._.
maybe rand method is not supported in XP version of ruby...
maybe try
Code:
(11..14).to_a.sample

or

[*11..14].sample
it will convert 11..14 range to array and then grab random member from that using .sample...

the second one might not works though since it might also not supported by xp ruby version too...
but it's worth a try 😀.

but this method have downside though... if the range is too big... it might take quite some time to process... but what i mean too big is quite big range... ten thousand or above... and if you're only working with small number the performance won't be noticed.

hope this help...
So the "rand" function only supports returning a float value between 0 and 1 (exclusive) if you don't supply a value, or it returns integers in the range 0-N (exclusive) if you supply a value of N.

But that's ok! We can still use that to make lots of different kinds of random number generators. So what you want is a random number from 11 to 14 (inclusive). Ok, that means we want a random number that's 1 one of four possible values (11, 12, 13, 14). So we can start by generating a random number with four possible values using 'x = rand(4)'. This gives us either a 0, 1, 2, or 3. Then we just have to shift this to the desired range by adding the base (11) as 11+0=11, 11+1=12, etc.

Now we could do this manually each time, but it's a lot easier to just write a small method that does this for us, and then we don't have to worry about it.

Ruby:
def rand_range(start_range, end_range, include_end = false)
    range = end_range - start_range
    range += include_end ? 1 : 0
    return rand(range) + start_range
end
So the "rand" function only supports returning a float value between 0 and 1 (exclusive) if you don't supply a value, or it returns integers in the range 0-N (exclusive) if you supply a value of N.

But that's ok! We can still use that to make lots of different kinds of random number generators. So what you want is a random number from 11 to 14 (inclusive). Ok, that means we want a random number that's 1 one of four possible values (11, 12, 13, 14). So we can start by generating a random number with four possible values using 'x = rand(4)'. This gives us either a 0, 1, 2, or 3. Then we just have to shift this to the desired range by adding the base (11) as 11+0=11, 11+1=12, etc.

Now we could do this manually each time, but it's a lot easier to just write a small method that does this for us, and then we don't have to worry about it.

Ruby:
def rand_range(start_range, end_range, include_end = false)
    range = end_range - start_range
    range += include_end ? 1 : 0
    return rand(range) + start_range
end

ohhhhh this is cool, i'll use this, thank you

Original thread: https://forums.rpgmakerweb.com/threads/help-me-with-very-simple-line-of-script-rpgmxp.128869/