23 posts
• Page **1** of **3** • **1**, 2, 3

**Posts:**17**Reputation:**6,778

B

14
S

4
G

8
"random(first_value,second_value)"

Something like "random(1,5)". But this will generate non rounded numbers like 3,412354

For round numbers use "round(random(1,5))"

Check this example out:

http://dl.dropbox.com/u/23138239/Random%20counter%20number.capxTuiii 2011-11-14 16:49:14

Something like "random(1,5)". But this will generate non rounded numbers like 3,412354

For round numbers use "round(random(1,5))"

Check this example out:

http://dl.dropbox.com/u/23138239/Random%20counter%20number.capx

**Posts:**61**Reputation:**2,683

B

22
S

4
G

3
I don't know if this is too pedantic, but you should use floor() with random() to generate random whole numbers.

round(random(1, 3)) will give:

1 to 1.5: 1

1.5 to 2.5: 2

2.5 to 3: 3

Note 2 has twice as big a range so is twice as likely to come up! If you want all numbers equally likely, use floor(random(1, 3)), which gives:

1 to 2: 1

2 to 3: 2

3 is now no longer a possible result, but at least 1 and 2 are equally likely to come up.Ashley 2011-11-14 17:38:52

round(random(1, 3)) will give:

1 to 1.5: 1

1.5 to 2.5: 2

2.5 to 3: 3

Note 2 has twice as big a range so is twice as likely to come up! If you want all numbers equally likely, use floor(random(1, 3)), which gives:

1 to 2: 1

2 to 3: 2

3 is now no longer a possible result, but at least 1 and 2 are equally likely to come up.

**Posts:**24,003**Reputation:**189,843

Scirra Founder

B

382
S

223
G

86
You could also use int(random(x)) indeed.

The trick here is that it would pick a random float number between 0 and X and return an integer (so a rounded value of the returned float number).

In the end it all depends to what you're doing.

Ceil will round up, floor will round down, int will automaticly ceil or floor.

This post by Ashley gives more info about the use of int().Kyatric 2012-01-06 12:42:28

The trick here is that it would pick a random float number between 0 and X and return an integer (so a rounded value of the returned float number).

In the end it all depends to what you're doing.

Ceil will round up, floor will round down, int will automaticly ceil or floor.

This post by Ashley gives more info about the use of int().

**Posts:**7,270**Reputation:**76,425

Moderator

B

273
S

100
G

71
**Posts:**3**Reputation:**281

B

3
**Posts:**286**Reputation:**1,988

B

15
S

4
G

1
23 posts
• Page **1** of **3** • **1**, 2, 3

## Who is online |

Users browsing this forum: delgado, iceangel, ketramtu18 and 1 guest |