User Tag List

Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 21

Thread: Random option with different probability

  1. #1
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)

    Join Date
    Sep 2018
    Posts
    24
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Random option with different probability

    Hello,

    I'm looking for some help with something or maybe just a nudge in the right direction. Here's what I'm trying to do:

    When player clicks certain item or icon I would like to give him 1 out of 4 options, but with different probability. For example, if a player clicks START MISSION, he would get one of 4 mission types (easy,normal,hard or very hard) but the chances would be 50% for easy,30%normal,20%hard and 10%very hard for instance. How would one accomplish something like this?

    Thanks for any help

  2. #2
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleiOS Export ModuleInstall Creator Pro
    Fusion 2.5 (Steam)
    elvisish's Avatar
    Join Date
    Oct 2014
    Posts
    824
    Mentioned
    19 Post(s)
    Tagged
    0 Thread(s)
    This will do just that, I set random range to be 1-indexed rather than 0-index so it's easier to see the percentage.
    Attached files Attached files

  3. #3
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    679
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    You could make a weighted random function by setting a string object.

    0 = easy
    1 = normal
    2 = hard
    3 = very hard

    then populate it like: 00000111223 for example, and then set a value to val(Mid$( string$( "String" ), random(Len( string$( "String" ) )), 1)) to get a random number from the string.

    weighted random simple.mfa

    a more robust approach is using a delimited string and the string tokenizer extension in the same fashion, only it allows you to use whole words or numbers with greater than 1 place (i.e 10). But for something simple this works good and is much faster than the list method others might recommend. You could alternatively use letters and numbers, and just set a second string to that same expression but without the val() conversion around it, then compare to the character you get for more options.

  4. #4
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    679
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    I turned it into an example i'll upload to the examples section: random probability.mfa

  5. #5
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Volnaiskra's Avatar
    Join Date
    Jan 2014
    Location
    www.sprykegame.com
    Posts
    2,558
    Mentioned
    133 Post(s)
    Tagged
    0 Thread(s)
    As it happens I was trying to figure out the same thing today, so I have a different method I can share. It's not as elegant and easy to tweak as @casleziro 's method, but it's contained in a single action, and is a lot faster due to not having to use strings (9 times faster, according to the profiler). If you only have to perform one or two of these in a frame, then I'd go with casleziro's method. But if you'll be performing 100 of these in a fastloop like I will, then this might be a good method, despite its crudeness.

    This action will return a number between 1-5, with 1 being very common and 5 being very rare:

    Set weightedRandomNumber to Max(1, RRandom( - 2, 1 ) + RRandom(0, 2) + RRandom(0, 2))

    It's relatively self-explanatory, but basically what is happening is that it'll only be 5 if the blue and the green and the orange portions all output their highest numbers (1, 2, and 2, respectively). This will only happen rarely. It's more likely that a lower number will result. A result of 0, -1, or -2 (all of which are possible) will be forced to 1 by the max(1, at the start, which makes 1 a very likely outcome.

    To get different ranges or probabilities, you can obviously change the numbers around or add/remove more rrandom() portions. But if you need to control your probabilities precisely to the last %, then I have no idea how you'd do that.

  6. #6
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    679
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    @Volnaiskra it's quite a bit more involved to get accurate percentage, but I was curious so I did it. Requires String Tokenizer extension (which is multiplatform!) and is most likely NOT fast due to loops and recursion. But it isn't slow enough to be noticeable at all. Maybe if you were working with a giant pool of items.

    There are now 2 delimited strings you populate: item pool and item weights. The method sums together all the weights and picks a random number between 1 and the sum, then recursively loops through the list, subtracting the weight of each item from that picked number until it is lower or equal to 0. The loop breaks when this happens and returns the current item at loop index. Doesn't support float weights, but you don't really need them. Also supports duplicate weights, and the weights can be any number. The higher the weight the more common the item.

    EDIT attached wrong file version

    updated: random with accurate weights_2.mfa

  7. #7
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Volnaiskra's Avatar
    Join Date
    Jan 2014
    Location
    www.sprykegame.com
    Posts
    2,558
    Mentioned
    133 Post(s)
    Tagged
    0 Thread(s)
    @casleziro your second example (post #4) gave me an idea to do something similar, but using values, so it'd be cheaper. You just create an active object whose purpose is to hold a pool of numbers in its altVals, then you just choose one of those altVals at random:

    numberPool : Set actualNumber to AltValN( "numberPool", RRandom(1, 15) )



  8. #8
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    679
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    @Volnaiskra neat optimization! You get the added advantage of being able to use numbers greater than 1 place width.

  9. #9
    Clicker Fusion 2.5Android Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    AftPeakTank's Avatar
    Join Date
    Apr 2013
    Location
    Greece
    Posts
    399
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)

    Another Solution for picking would be...

    With all the respect to all the previous answers, I would do it like this.

    First, properly distribute your percentages. You can't have 50,30,20,10, cause the sum is 110%. That's not realistic. However you could do it if you want the odds to be 50 of 110, 30 of 110 etc.

    But let's talk about a 100% sum. Let's distribute the difficulty levels:

    1 - easy - 50%
    2 - normal - 30%
    3 - hard - 15%
    4 - very hard -5%

    50+30+15+5 = 100 so we are ok.

    Now if you ask for a random number between 1 to 100, you can have the first 50 numbers be easy, the next 25 the normal etc. meaning:

    1. 1-50 -> easy
    2. 51-80 -> normal
    3. 81-95 -> hard
    4. 96-100 -> very hard

    In order for this to work properly I have to assume that the random pick of fusion is indeed following the statistical rules (it is a true random with equal odds to pick any of the numbers).

    Therefore the code is the following:
    randompick.png

    Here is the MFA if you want to test. - randompick.mfa

  10. #10
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    679
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    @AftPeakTank perfectly valid solution. I think it gets messy if you want many items, since fitting them all into 100 while also having decent weights is difficult. For something as small as the example, there's no reason you shouldn't use this method if you prefer.

    a note though: reading from counters is slower than reading from an active's alterable value! I see counters used a lot around the forums so I figured I would mention it.

Page 1 of 3 1 2 3 LastLast

Similar Threads

  1. Allow offline option disable. How enable this option?
    By pradeep in forum HTML5 Export Module 2.5
    Replies: 2
    Last Post: 5th March 2015, 10:14 AM
  2. Replies: 0
    Last Post: 14th February 2015, 05:02 PM
  3. Best way to randomize with a probability table
    By Boba Fonts in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 11th August 2011, 06:25 AM
  4. Probability example
    By LB in forum File Archive
    Replies: 1
    Last Post: 18th April 2010, 10:01 AM
  5. Probability Based Events Example
    By Atom in forum File Archive
    Replies: 0
    Last Post: 20th October 2008, 08:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •