# How do I make random give a full number?

0 favourites
• 5 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
• so, im trying to do something that is like this:

on button pressed then add random(1,11) to variable

but it have a problem, it gives something like: 1.4245436564 or 3.423565534634 wich really breaks the whole game, can i make random only give a full number? help!

major problems: texts go invisible because they are full, money breaks compleataly(it gives a negative number and the text go invisible becuase its full)

#### Tagged:

• int(random(1,11)) will give the numbers 1 thru 10.

• I think you'll want round(random(1,11))

int(random(1,11)) will just chop off everything after the decimal giving 1-10.

round returns the closest integer so that 10.6 = 11 and 10.4 = 10 so you get 1-11

ceil returns the next highest integer so that 10.1 = 11 (rounds up) and you get 2-11

floor returns the next lowest integer so that 10.9 = 10 (rounds down) and you get 1-10

• No, don't use round(), it will skew your results.

Pretend random returns single decimal point values. So 0.0, 0.1, 0.2, etc.

Using round() will return 0.0, 0.1, 0.2, 0.3, 0.4 as 0, but 0.5-1.4 will return 1. That pattern repeats until the other end, where the last number is also only half as likely to show up. The most accurate way to get an integer is to use int(random) (or floor). Then all numbers are equally likely.

• ## Try Construct 3

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

Construct 3 users don't see these ads
• No, don't use round(), it will skew your results.

Pretend random returns single decimal point values. So 0.0, 0.1, 0.2, etc.

Using round() will return 0.0, 0.1, 0.2, 0.3, 0.4 as 0, but 0.5-1.4 will return 1. That pattern repeats until the other end, where the last number is also only half as likely to show up. The most accurate way to get an integer is to use int(random) (or floor). Then all numbers are equally likely.

If his random, as he says it from 1-11 then it should not return anything less than 1. Were his random 0-11 then yes, it would return a 0-1.

But I see what you're saying. I just never worried about that difference that much. I used ceil or floor.

• 5 posts