Lua Script: "Random Numbers" (easy)

@Xavion Yeah, I have somewhere a knot in my brain…

My understanding is that this line:

local random_number=math.random(0,100)

will generate a number between 0 and 100. Which is what I want, as there is might happen somewhere between 1 and 100 times, but there is also the option that it is not happening. So this should be 101 options, no?

With this line:

if (random_number<probability_plan) then

I am checking if the random number is below the probability which should be achieved based on the user input. Here it should actually be <=, because it should also count the same probability as a fulfilling the condition. So adjusting “=” to “<=” is something which would be understandable to me, to cover the probability of 100%. However…

Now let’s take a look on the extremes of 0 and 100. For 100 “<=” would work and it would result in a positive count for probability. For 0, this formula would not work as a 0 would result in a fulfillment of the condition, which is wrong. So, actually I might leave the “=” as it is and increase the desired number to 101 (so if the random number is 100, it will be sufficient to fulfill the condition), instead of decreasing the random generated number to 99, no?

Update: Changed some wording to make it more clear what I am thinking.

Can’t wait till I get more time to check back here and watch’ ya guys go back and forth. I’m a very low level hobby guy and I’ve been looking for a way to learn Lua better.

Every pass option should have a corresponding number that is the maximum for it, 0 is special and doesn’t get a number at all but every thing else should get one. This can be done with <= and 1,100 so that every number in 1,100 gets a corresponding value from the random plus all nums below so it works. Since we’re using integers however we can change the <= to a < and the 1,100 to a 0,99 without breaking it s they are functionally the same.

at the moment i’m using sublime text 2, and have added LUA as a build system, but when i try to execute the code, i get and error telling me that i cant run the for loop for ever. i know this is because of the amout_runs variable never gets a value. Sublime simply wont stop and wait for my input, is there a way to fix this?

If you cannot enter the values manually (via io.read), just align fixed values to them, e.g. replace lines 3-7 with something like…

probability_plan=75
amount_runs=10