Hi. How can i set a range of numbers for random expession? for example, i want to get a random number between 5 and 10.
random(5,10) or round(random(5,10)) if it needs to be an integer
Develop games in your browser. Powerful, performant & highly capable.
Thank you. I tought, in this case i will get 5 or 10. But it works the way i want.
Yes no problem (x,y) in this case is the range. Check out the manual for more info!
Using round() with random is not a good idea. The results distribution will not be uniform.
If you need an integer number between 5 and 10, use int(random(5,11))
Here is a small project demonstrating the issue:
dropbox.com/s/mkt4ldmpsn0quks/RandomDemo.capx
Here is a small project demonstrating the issue: https://www.dropbox.com/s/mkt4ldmpsn0quks/RandomDemo.capx?dl=0
https://www.dropbox.com/s/mkt4ldmpsn0quks/RandomDemo.capx?dl=0
Thank a lot. it's realy interesting
> random(5,10) or round(random(5,10)) if it needs to be an integer Thank you. I tought, in this case i will get 5 or 10. But it works the way i want.
> random(5,10) or round(random(5,10)) if it needs to be an integer
If you hypothetically did want 5 or 10 at random you could use choose(5,10)
Thats a damn good example.
Thanks for doing it.