how to randomize none following numbers like 1,3,4 with expression ?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Hi

    i found question like this in the archive, but i still need help to understand how to calculate it:
    i need my counter to generate random number between 1,3,4 (without number 2) and in another event between 1,2,4 (without number 3).
    can i do it with the calculator, like set counter into random using calculator expression?

    i need simple way please :)

    thanks ahead,
    p.

  • thanks :)
    can you please explain to me how it works ?
    i know that the random (3) gives you 0,1,2 right ?
    but how the rest of the expression works and what does Round means ?
    and how can i do 1,2,4 (without number 3) ?

  • Round(( Random(3) * 1.5 ) + 1)

    Round(( 0 * 1.5 ) + 1) = 0+1 = 1
    Round(( 1 * 1.5 ) + 1) = 1.5+1 -> rounded down to 2
    Round(( 2 * 1.5 ) + 1) = 3+1 = 4

    so the result will always be 1,2 or 4

  • what does Round means ?


    Round value converts a floating point number into a integer number by rounding the value to the nearest integer number.
    So for example I want to round 3.5 then it would be 4, round 3.7 would be 4 too
    But if I round 3.4 or 3.3...etc it would be 3

    Basically if the decimal number is higher or equal 5 then it would round it to the next nearest integer number, otherwise it would round it to the same number but with no decimals (true number/integer)

    Game/App developer, artist and a community contributor.
    You can support my work on: Please login to see this link.

  • can you please explain to me how it works ?

    So you got this:
    Round(( Random(3) * 1.5 ) + 1)

    Random(3) can give you 0, 1, 2
    0 * 1.5 = 0
    1 * 1.5 = 1.5
    2 * 1.5 = 3
    Then we add 1... Resulting in: 1, 2.5, 4
    If a number decimals are lower than .5 it will round to .0, if it's equal or greater than .5 it will round to the next integer, so 1.5 becomes 2.0, Fusion removes the .0 since it has no meaning, so it's just 2.

    So in the end you got: 1, 3, 4

  • Yeah, the problem with a math-based solution is that if you later decide that you need different set of numbers, you'll need to work out a whole new formula (not always easy). Plus, if you come back and look at the event months later, it won't be obvious what the formula even does.

    If your set of numbers is dynamic (if you're frequently adding, removing or changing numbers at runtime), then a List object or other extension is probably the best option.

    If it's fixed, or very simple, I'd just use string functions:

    // For 3 single digit numbers
    val( mid$( "134", random( 3 ), 1 ))

    // For 3 two-digit numbers - note the leading zeroes
    val( mid$("05,06,14", random(3) * 3, 2 ))

    It's simple, easily adjustable and very clear as to what it does.


    // If you want to use the same method with a dynamic set of numbers, you can store them in an alterable string - I've done this a lot in my random maze generation examples.
    val( mid$( alterableString , random(len( alterableString )), 1 ))

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!