# Random(x,x), how to make it choose integers over doubles

0 favourites
• 6 posts
• Hey! So basically, I am making a game where a selection at the beginning of the game is required. I initially wanted to make it so I could use the random(parameters) function would work; however the issue is I the random function can return a result of a double (2.5 for example), when I'm really requiring it to return an integer only. Is there any way possible or do I have to go through the tedious practice of putting in conditions of > than and < than?

Thank you.

• I'm not really sure i understood, but you could try something like this.

if you only want integers returned you can use round, floor, or ceil.

round(random(1,10)) will give you integers between 1 and 10

floor(random(1,10)) will give you integers but rounded down. 2.5 will be 2

ceil(random(1,10)) will give you integers but rounded up 2.5 will be 3

Was that what you were looking for?

Otherwize you can use the choose instead.

choose(1,2,3,4,5,6,7,8,9) or how many parameters you want. it will pick a random one of those.

• round(random(1,10)) looks right, will post back when I implement it!

Thank you

• IN case you missed the edit:

Otherwize you can use the choose instead.

choose(1,2,3,4,5,6,7,8,9) or how many parameters you want. it will pick a random one of those.

• I am using choose as of now, however the numbers will go up to at least 30-50 soon, so random(1,50) may be more practical

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• IN case you missed the edit:

Otherwize you can use the choose instead.

choose(1,2,3,4,5,6,7,8,9) or how many parameters you want. it will pick a random one of those.

You forgot int()

I would choose random() over choose() for returning a value from a large range. Easier on the eye, easier to work with and probably better performance.

• 6 posts