How to get a random number based on specific ones?

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 Guys!

    I need to get a random number based on previously specified numbers, something like "Random (1,3,5,12)".

    Does anyone know how to do it ?, I would like to do it directly from the expression calculator, if possible.

    Thanks in advance!

    Hispanic Community of MMF2 and CF2.5 / Comunidad Hispana de MMF2 y CF2.5: Please login to see this link.

  • You can do it with a list getting a random line from the amount available, or splitting a string with the numbers using the comma as token with string tokenizer then getting it with a random number for the index.
    Directly from expression calculator wouldn't work for one simple reason: numbers can have different amount of digits, you can't predict this.

  • the list is the easiest way; create list with each line representing one of the numbers you want to choose from(eg; 5 lines with a different result); do a normal random(1-5); and pick the line from the list. and VAL(the list$ number)

  • Thanks guys! Doing it with a list is a good idea, but I don't like to use other objects than the basic ones if it is not really necessary, I always try to make things as simple and efficient as I can.

    Since it is not possible through the "expression calculator", I did it using the alterable values of an Active to store the already defined values, this way it can be done in a single line and it is very simple.

    I attach the .mfa in case someone has the same question and needs it.

  • The list is definitely the easiest way, but if you were really intent on not using any numbers, you could store your numbers in a global string, and then use Left$ and Right$ to snip out a part of that string and convert it to a number, like Please login to see this link.

    It's not as elegant as using the list object though, but it can be done without using another object if you wanted

  • The list is definitely the easiest way, but if you were really intent on not using any numbers, you could store your numbers in a global string, and then use Left$ and Right$ to snip out a part of that string and convert it to a number, like Please login to see this link.

    It's not as elegant as using the list object though, but it can be done without using another object if you wanted


    [MENTION=19502]marbenx[/MENTION], that method is great!
    It's true that the list is the easiest way, but I always try not to use objects if it's not really necessary. The way you have done it seems great to me, just what I was looking for. Thank you!

    Hispanic Community of MMF2 and CF2.5 / Comunidad Hispana de MMF2 y CF2.5: Please login to see this link.

Participate now!

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