User inserts percentage, how can I make that number the probability of something happening?
TheShatteredBox
Member Posts: 21
Hello!
I know this idea is kind of weird but it's really important I get this done. The idea is that the player inserts a percentage (e.g 12%) that stands for the odds of something happening. Then they press a button as many times as possible until that thing happens. My question here is, how can I make it so that the number the user inserts is a percentage and how can I make that whole probability system work? Any help?
Thank you! Have a nice day
I know this idea is kind of weird but it's really important I get this done. The idea is that the player inserts a percentage (e.g 12%) that stands for the odds of something happening. Then they press a button as many times as possible until that thing happens. My question here is, how can I make it so that the number the user inserts is a percentage and how can I make that whole probability system work? Any help?
Thank you! Have a nice day
Comments
A Table with 100 Rows or 100 Columns set to Boolean datatype values will take care of this Make all values False initially. After inputting a number N as percentage, simply change the values of the first or last N Rows or Columns of your Table with True. Then Randomize between those Rows or Columns every push of the button
That's just one way of doing it, and I hope you got it. Good luck!
EDIT: I realize the solution I gave limits you too much as it forces you to have 100 possibilities per push. I apologize, and at best I hope it was able to pique someone else's interest in solving your dilemma bookmarking this thread now.
If AAA => Random (1,100) then "that thing happens".
But if you want to get this to 12% (say, user entered value is 12) you need to run that for 12 times. But still this is not that "awesome" because there is still a chance even when 100% is entered, and this gets executed 100 times and there is still a slim chance you wont get "that thing happens"
Enter 12, then compare that 12 to a random number between 1 and 100, only 12% of our random selection (on average) will fall below (or will be equal to) 12. AAA = 100
If AAA => Random (1,100) then "that thing happens"
This will return a "that thing happens" every time it's run (as it should).
Change Attribute: myLimit To: 12
When mouse is down
-- When myLimit ≥ random(1,100)
----Display Text: Yes!
--Otherwise
----DisplayText: No!
I tought it was only "equal"
Well, that clears that up.
P.S: On most of the languages it is ">=" not the other way around.
P.S2: Your way is really smart.
Note: I changed the symbol from a '>=' to a '≥'
Ahah that's weird I didn't notice you posted before me and I was talking about @Socks 's example.
You guys have elegant ways of solving problems as it seems. But still, not as much as @CodeWizard probably.