How to generate numbers from variables, without the lag of an overly complicated process.
(i.e. <>Variable X = Random Number Between 1 and Another Variable)

Well, I stumbled upon a quick little tidbit of an idea when working on my latest little project. (most likely to be abandoned eventually, as these things tend to go!)

Regardless, the method I've heard and seen of for generating random numbers is to make a loop that will occur for the number of times that the highest number can be, and randomly generate a 1 or a 0.

<>Loop

<> Variable 01 = Random Number Between 0 and 1

<> Variable 02 = Variable 02 - 1

<> Conditional (Is Variable 02 <= 0?)

<> <>Break Cycle

<>End Loop

While this does what we want, it also causes incredible lag. Imagine generating a high number, with something like 5,000 as the cap? It'll take an incredibly long time, and the problem is that such is only ONE number.

How do we get around this? Well, if we think about it, we want to randomly generate a number between something, so we could take a percentage of it. For example, generating between 1-10 could be determined as 1 on 1-10, 2 on 11-20, and so forth. So, what we need to do is put this in terms for the usage alongside with variables.

What we'll do is take a Variable and store the random number's maximum value in it. In another Variable, randomly generate a number between 1 and 100. Multiple these two numbers together, and divide by 100. This will 'emulate' the idea of a floating-point (generating between 1-100 and dividing by 100 will do this) number.

Obviously, there are some limitations. For starters, the number has to be 99,999 or less. Why? Well, if you have anything greater and multiple it by 100, you'll be beyond the maximum value of a Variable. Thankfully though, I don't think anyone will really need to be generating a value that high. There will also be some problems generating between 1 and that number, since there's a chance it could be 0 on low-capped numbers. ( 1 * 1 / 100 == 0 ) So, it might be a good idea to lower the cap number by one, and add one at the end.

All in all though, it'll save the game a lot of time and allow you to generate random numbers, based on variables!

Regardless, the method I've heard and seen of for generating random numbers is to make a loop that will occur for the number of times that the highest number can be, and randomly generate a 1 or a 0.

<>Loop

<> Variable 01 = Random Number Between 0 and 1

<> Variable 02 = Variable 02 - 1

<> Conditional (Is Variable 02 <= 0?)

<> <>Break Cycle

<>End Loop

While this does what we want, it also causes incredible lag. Imagine generating a high number, with something like 5,000 as the cap? It'll take an incredibly long time, and the problem is that such is only ONE number.

How do we get around this? Well, if we think about it, we want to randomly generate a number between something, so we could take a percentage of it. For example, generating between 1-10 could be determined as 1 on 1-10, 2 on 11-20, and so forth. So, what we need to do is put this in terms for the usage alongside with variables.

What we'll do is take a Variable and store the random number's maximum value in it. In another Variable, randomly generate a number between 1 and 100. Multiple these two numbers together, and divide by 100. This will 'emulate' the idea of a floating-point (generating between 1-100 and dividing by 100 will do this) number.

Obviously, there are some limitations. For starters, the number has to be 99,999 or less. Why? Well, if you have anything greater and multiple it by 100, you'll be beyond the maximum value of a Variable. Thankfully though, I don't think anyone will really need to be generating a value that high. There will also be some problems generating between 1 and that number, since there's a chance it could be 0 on low-capped numbers. ( 1 * 1 / 100 == 0 ) So, it might be a good idea to lower the cap number by one, and add one at the end.

All in all though, it'll save the game a lot of time and allow you to generate random numbers, based on variables!