User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17

Thread: Five Random But Different Numbers Out of 72

  1. #1
    Clicker Multimedia Fusion 2 DeveloperHTML5 Export ModuleSWF Export ModuleInstall Creator Pro
    drnebula's Avatar
    Join Date
    Jul 2006
    Location
    Pennsylvania, USA
    Posts
    908
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Five Random But Different Numbers Out of 72

    I want to choose 5 random numbers out of 72 but they must be different. Does anyone have a simple way of doing this? I've started a method but it is becoming rather long winded and complex. I know there must be an easier way. Any help appreciated.
    Steve

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export Module
    Chrille's Avatar
    Join Date
    Jul 2006
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The easiest method would probably be using a loop and a list object.

    Code:
    + Trigger Randomize
    - Start Loop "randomize"
    - Clear List
    
    + On Loop "randomize"
    - Set Value to Random(72)
    
    + On Loop "randomize"
    + Compare Two General Values: FindStringExact( "List", Str$(Value), -1) == -1
    - Add Line to List: Str$(Value)
    
    + On Loop "randomize"
    + Compare Two General Values: List Get Number of Lines == 5
    - Stop Loop "randomize"

    This is probably the easiest method. You could skip the list and use an array or something like that instead, you'd have to use more loops though.

  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)
    I expanded on Chrille's example and made it a bit more flexible and efficient (the list object is very slow, regardless of what you use it for, so I substituted it with an active object's string instead) and turned it into more of a function than anything. Now it does this:

    -return any amount of numbers within a custom range, and choose whether or not they will be different or allow duplicates

    randomizer function.mfa

  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)
    Pfft, I got so caught up in actually making the function that I forgot to think about how to actually use those values . I really need to stop embarrassing myself like this.

    String tokenizer will do the trick!

    Updated (i'll need to update my submission to the tutorial thread as well when it gets approved ) : randomizer function2.mfa

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Cool ideas guys!
    Nice widget Casleziro!
    Very useful also as random pool ext. is windows only.

    This could require a little modification to avoid duplicates shortening the output
    (less results than requested ones)
    like this:

    randomizer function_1.mfa

    (this was already present in Chrille's idea, I guess the loop was fired "infinite" times)

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export Module
    Chrille's Avatar
    Join Date
    Jul 2006
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hah, yes I forgot mentioning that little detail

  7. #7
    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)
    Ah thanks schrodinger, I didn't think of that!

  8. #8
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Maybe also a "prevent crash" if people fires a request for more numbers than the range they requested (would result in infinite loop)

    like:

    on loop "random"
    +loopindex("random")=0
    +max random - min random < number of returned values
    >>> stop loop "random"
    >>> set "result string" to "error! too small range"

    just an idea,
    one could think at other ways to crash so this may be pointless..
    (or would require to take into account some more cases to be 100% sure)
    Just that I'm a little paranoid with firing endless loops I guess


    Very cool widget/concept!

  9. #9
    Clicker Multimedia Fusion 2 DeveloperHTML5 Export ModuleSWF Export ModuleInstall Creator Pro
    drnebula's Avatar
    Join Date
    Jul 2006
    Location
    Pennsylvania, USA
    Posts
    908
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everyone for some great ideas. I'll learn a lot from going over your code. I've been coding multimedia fusion projects for 10+ years but still feel like a novice. I have an engineering degree but back before they even had calculators let alone computers. One of these days I ought to take some programming courses, but I'm having too much fun playing with Multimedia Fusion.
    Steve

  10. #10
    Clicker Fusion 2.5Android Export ModuleSWF Export Module
    Ziplock's Avatar
    Join Date
    Oct 2013
    Posts
    448
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Didn't get to this thread before it was solved (was at work), but I thought I'd share my technique too:

    Here I have two objects, one "Random" which is used to pick the numbers, and the other is "Hero," used to store the values in alt.val A-E.

    Start of Frame:
    -> Start Loop "Create Random" 72 times
    -> Start Loop "Designate Random Values" 5 times

    Start of Frame:
    -> Start loop for each one of "Random", loop name "Destroy Random Objects"

    On loop "Create Random"
    -> Create "Random" at (0,0)
    -> Set Alterable Value A to LoopIndex("Create Random")+1

    On loop "Designate Random Values"
    + Pick one of "Random"
    -> Set "Hero's" Alterable Value (LoopIndex("Designate Random Values")) to Alterable Value A of "Random"
    -> Destroy "Random"

    On each one of "Random", Loop Name "Destroy Random Objects"
    -> Destroy "Random"
    Attached files Attached files

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Random numbers
    By Techspec in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 4th May 2013, 02:27 AM
  2. Random Numbers and expiring the result numbers.
    By Corlen in forum Multimedia Fusion 2 - Technical Support
    Replies: 0
    Last Post: 26th April 2013, 04:11 PM
  3. Random numbers help
    By Atherton in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 5th January 2010, 12:41 PM
  4. Random Numbers Greater then Random Numbers...
    By Hordolur in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 15th April 2009, 06:24 AM
  5. random numbers
    By delusan in forum The Games Factory 2 - Technical Support
    Replies: 4
    Last Post: 24th March 2007, 05:09 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
  •