Not signed in (Sign In)

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorpuzzle geek (Advanced Member)
    • CommentTimeApr 7th 2013
     
    I'm making a big level, and I need random numbers like: 1/3 of the time, X happens. or 3/7 of the time, Y happens, 1/7 of the time Z happens, and the remaining 3/7 of the time, W happens. I will be needing a lot of them, so something that can be reproduced in mass would be apreciated.-----------------
    puzzled
    •  
      CommentAuthorTheDudeFromCI (Advanced Member)
    • CommentTimeApr 7th 2013 edited
     
    Number > Random > Random Integer Between

    Just choose a random number between 1 and 7, inclusive.
    if its 1 - 3, its Y
    4, Y
    5 - 7, Z-----------------
    Orange is my favorite number.
    • CommentAuthorpuzzle geek (Advanced Member)
    • CommentTimeApr 7th 2013
     
    Eh? I don't understand.
    I understand how to trigger it, but i can't figure out how to get it to trigger something else, right now, i basiclly learned nothing.
    Not to be rude, or anything, the dude, but I just don't understand.
    Example: In my level there is an area where you have to search the grass for a trapdoor.
    I want 1/5 (one-fifth) of the time the trapdoor is found. the other 4/5 of it, nothing.
    Right now, with what i know, i have a button labled "search grass", and thats it.
    demonstrations would be apreciated most, where i could load it in the editor and figure it out.-----------------
    puzzled
    •  
      CommentAuthorBioManiac R2 (Moderator)
    • CommentTimeApr 7th 2013
     
    look at this and learn from it :)

    •  
      CommentAuthorTheDudeFromCI (Advanced Member)
    • CommentTimeApr 7th 2013
     
    darn, >.>

    I'm a horrible teacher. Always have been. lol-----------------
    Orange is my favorite number.
    •  
      CommentAuthorBioManiac R2 (Moderator)
    • CommentTimeApr 7th 2013
     
    what you said made sense to me ... :/ but then again I knew what to do.. :/
    • CommentAuthorXyuzhg (Moderator)
    • CommentTimeApr 8th 2013 edited
     
    Haha, being a teacher is difficult sometimes.
    I'll explain TheDude's method in more detail.

    The first step is to use the random integer function.
    In your case, because you have probabilities with the common denominator 7, you want 7 possible results for the random integer.
    The easiest way is just to take the numbers from 0 to 6. You would have this in your code as:

    local[x:"NAME"] = FastIntegerRandomBetween (0, 7)

    The reason why the limits are from 0 to 7 is because the upper limit is exclusive (does not include the 7 itself).
    So, the variable will be assigned either 0, 1, 2, ... 5, or 6.

    Now you need to do a few comparisons.
    Because you have a 3/7 chance that Y happens, then it makes sense if Y happens if the random variable is 0, 1, or 2.
    So make Y happen if the variable is less then 3.

    There's only a 1/7 chance that Z happens, so it can be assigned just one number. It makes sense if it is simply 3.
    Thus, make Z happen if the variable is equal to 3.

    Then there's another 3/7 chance that W happens, so we can just let it be any of the remaining numbers: 4, 5, or 6.
    So, make W happen if the variable is greater than 3.
    Otherwise, you could have W execute in an else statement.

    ------------

    I actually made two custom functions based on probabilities for fun (written in v1.60):

    One of them is a very simple boolean assign function (the code is very easy to read, as it's only three lines).
    The other one is a bit more complicated, and is a string assign function.

    The string assign function has two inputs, both of which are expressed like ratios (with colon separators).
    The first input is the list of output results, which describes the possible string outcomes for the function.
    For example, if your possible results are Y, Z, and W, then you'd list the results as Y:Z:W.
    The second input is the list of probabilities, expressed purely as a ratio (you can use noninteger values).
    For example, taking the probabilities above, you'd input 3:1:3 into the second part.

    Here's an example of my string custom function in action:


    I personally recommend that you avoid using my custom function, as it is almost always more efficient to describe the probabilities out like above.
    But you can still use it however you like, as it can handle any number of possible results.-----------------
    Hopefully PA is inconsistent.
    •  
      CommentAuthorTheDudeFromCI (Advanced Member)
    • CommentTimeApr 8th 2013
     
    TheDudeFromCI = Mind blown-----------------
    Orange is my favorite number.
    •  
      CommentAuthorBioManiac R2 (Moderator)
    • CommentTimeApr 8th 2013
     
    too much explanation xyuzhg lol, i think my example is easier to understand :P
    • CommentAuthorXyuzhg (Moderator)
    • CommentTimeApr 8th 2013
     
    Hehe, I think I might have taken it too far. xD

    I like to overdo things.-----------------
    Hopefully PA is inconsistent.
    • CommentAuthorpuzzle geek (Advanced Member)
    • CommentTimeApr 8th 2013 edited
     
    thank you bio, i loaded it into the editor, messed around, until i figured it out. I now should be posting my cool level withon the week.
    oh, and thanks!-----------------
    puzzled
    •  
      CommentAuthorTheDudeFromCI (Advanced Member)
    • CommentTimeApr 8th 2013
     
    @xyuzhg
    lol-----------------
    Orange is my favorite number.