Generating Random Numbers Between 0.000 and 100.000

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 Folks - I hope you can help. I am writing a chemistry program and have to generate random numbers between 0 and 100 with 3 decimal places. I tried using the RRandom command in the Expression Editor, but I only get whole numbers.
    I solved the problem, but want to know if there is an easier solution.
    Here is my solution...
    I created 3 counters called IntPart, DecPart, TotalNum
    I created 3 strings called IntString, decString, TotalString
    Using the Random command I create the IntPart value between 0 and 100 and then I create the DecPart value between 0 and 1000.
    Then using the Str$ command, I convert each counter to a string (setting the Alterable Strings).
    Then I combine the IntString and the DecString with a decimal inbetween to produce a the TotalString.
    Finally, I convert the TotalString to a number with the Val command in the TotalNum counter .
    Is there a more direct way to get these random numbers?
    Thanks for your time.
    - Rich

    <span style="font-weight: bold"><span style="font-style: italic">'Til Later - RichC</span></span>

  • Isn't there the possibility of adding 1 using that setup? Because 1000/1000.0 would return 1. Maybe this instead: RRandom(0,100) + (RRandom(0,999)/1000.0). It will only return 100.999 worst case. And if you want to only return between 0-100 and not 100.999, then use this: Min(RRandom(0,100) + (RRandom(0,999)/1000.0),100)

    Best person at writing incomprehensible posts. Edits are a regularity.

    Edited 3 times, last by casleziro (May 11, 2020 at 6:27 PM).

  • dividing by 1000.0 casts it into a float even if the math would result in a whole integer.
    for example, 1000/1000.0 = 1.000, instead of 1

    if you want to change a number into a float without much hassle, you can always just add a {*1.0} to an expression. Once a number is a float, any further expressions with it as a parameter will turn the results of math with it into floats, unless you cast it back to an integer using functions like int(), ceil(), floor() or round()

  • [MENTION=5821]Pixelthief[/MENTION] I see. Thank you for that info.

    What I was referring to was the possibility of the expression returning 101, however. Would Min(x, 100.000) work in my solution?

    Best person at writing incomprehensible posts. Edits are a regularity.

Participate now!

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