User inserts percentage, how can I make that number the probability of something happening?

TheShatteredBoxTheShatteredBox Member Posts: 21
edited April 2013 in Working with GS (Mac)
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

Comments

  • TheGabfatherTheGabfather Member Posts: 633
    edited April 2013
    If it's a simple draw-type game of luck (eg. drawing from a deck of cards and hoping to get a Jack of any) you can probably settle with Tables.

    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.
  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2013
    Enter a value into attribute AAA, this will be our percentage.

    If AAA => Random (1,100) then "that thing happens".
  • cbtcbt Member Posts: 644
    Enter a percentage value into an attribute (AAA)

    If AAA => Random (1,100) then "that thing happens".
    This is only 1%
    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"

    :)
  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2013

    This is only 1%
    If you enter 20, then select a random number between 1 and 100, 80% of this random selection will be larger than (or equal to) 20 - ie: only 1 in 5 (or 20%) of this random selection will be smaller than 20 - and we then check for that.
    But if you want to get this to 12% (say, user entered value is 12) you need to run that for 12 times.
    You'd only need to run it once for the chances of a positive result to be 12% (1/8.333), every time you ran it it would be 1/8.333.

    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.
    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"
    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).
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited April 2013
    Maybe a concrete example will help:

    Change Attribute: myLimit To: 12
    When mouse is down
    -- When myLimit ≥ random(1,100)
    ----Display Text: Yes!
    --Otherwise
    ----DisplayText: No!
  • cbtcbt Member Posts: 644
    edited April 2013
    Oh, it is "greater or equal"

    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.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    @cbt -- It is saying if 'myLimit' is greater than (or equal to) the random number. (But it really means that the the random number is less than (or equal to) 'myLimit'.)

    Note: I changed the symbol from a '>=' to a '≥'
  • cbtcbt Member Posts: 644
    @RThurman

    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. :D
Sign In or Register to comment.