User Tag List

Results 1 to 7 of 7

Thread: Best way to randomize with a probability table

  1. #1
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleSWF Export ModuleUnicode Add-on
    Boba Fonts's Avatar
    Join Date
    Jan 2009
    Location
    Northern Italy
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Best way to randomize with a probability table

    I'm still wondering which is the best -the most "clean"- way to achieve this: let's say I want to randomize the bonus coming out of a destroyed chest. There's a 60% it's some magic item, a 30% it's a time bonus and a 10% it's an extra life.
    To date I've

    -set a given "chance Value" to Random 100,
    then

    -if it's between 1 and 60 create the first item,

    -between 61 and 90 the second,

    -between 91 and 100 the third.

    It certainly worked, but I'm sure there's a better way to do that! I'd like to use less and better code lines.

  2. #2
    Forum Moderator

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator Pro
    nivram's Avatar
    Join Date
    Jul 2006
    Location
    Bandon, Oregon
    Posts
    6,773
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)

    Re: Best way to randomize with a probability table

    Boba. Looks good to me and its clean, but of course there are many ways that different people code. If I may suggest. Code the way you feel is comfortable. If other people get involved you will be squrming like a worm and feel uncomfortable.
    ​458 TGF to CTF 2.5+ Examples and games
    http://www.castles-of-britain.com/mmf2examples.htm

  3. #3
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleSWF Export ModuleUnicode Add-on
    Boba Fonts's Avatar
    Join Date
    Jan 2009
    Location
    Northern Italy
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Best way to randomize with a probability table

    Thank you. Glad to hear it's ok, but I was wondering if maybe some extension could help to reduce the whole thing to a couple of lines. I'm open to suggestions and I always seek help 'cause my path to master MMF2 is very long!

  4. #4
    Forum Moderator

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator Pro
    nivram's Avatar
    Join Date
    Jul 2006
    Location
    Bandon, Oregon
    Posts
    6,773
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)

    Re: Best way to randomize with a probability table

    Hi again Boba. You really don't need an extension for this coding. Also, consider your path as not including extions when you do not need to for great code.

    On my website examples, there are probably 150 examples not using extensions.

    Marv
    ​458 TGF to CTF 2.5+ Examples and games
    http://www.castles-of-britain.com/mmf2examples.htm

  5. #5
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleSWF Export ModuleUnicode Add-on
    Boba Fonts's Avatar
    Join Date
    Jan 2009
    Location
    Northern Italy
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Best way to randomize with a probability table

    I know, but that's because you're notoriously great at coding! And the same can't be said for me.
    Anyway I'll carry on my solution until it's working!
    thanks

  6. #6
    Clicker Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleXNA 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)
    gkinfinity's Avatar
    Join Date
    May 2011
    Location
    USA
    Posts
    284
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: Best way to randomize with a probability table

    I've personally always used a method similar to what you're using Boba. (Although I'd probably simplify the numbers for the example you used since 60, 30 and 10 are all divisible by 10. It's not at all necessary though and you're method should work just as well)

  7. #7
    Clicker Multimedia Fusion 2SWF Export Module

    Join Date
    Sep 2006
    Posts
    1,544
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Best way to randomize with a probability table

    For a more, uh, versatile system, what you should do is give each event a probability, relative to each other, then sum up the total probabilities, choose a random number in that range, and call the event that corresponds to that range. With your example, that would be probabilities of 10, 30 & 60 for 3 events. But you could easily have it be a 10, 30, 60, 50, 20 & 5 done by choosing from random(175).

    Then, its possible to adjust the probabilities of each item by a weighting factor. For example, you might multiply or subtract the rarities of each item by the difference in 'level' of that item from the chest or area where it dropped. So that your 10/30/60 distribution might become an 8/36/26 distribution. That can be a useful thing if you want to have loot that is more often relevant for the level of your character, but still have everything 'spawnable'

Similar Threads

  1. The Randomize Function
    By Godspeed8118 in forum Multimedia Fusion 2 - Technical Support
    Replies: 6
    Last Post: 4th April 2013, 03:19 AM
  2. Randomize Array
    By Keith in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 9th September 2011, 04:46 PM
  3. Probability example
    By LB in forum File Archive
    Replies: 1
    Last Post: 18th April 2010, 10:01 AM
  4. Probability Based Events Example
    By Atom in forum File Archive
    Replies: 0
    Last Post: 20th October 2008, 08:08 PM
  5. Randomize option
    By RagingTiger in forum File Archive
    Replies: 7
    Last Post: 13th October 2006, 05:11 AM

Posting Permissions

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