11 posts
• Page **1** of **2** • **1**, 2

**Posts:**23,997**Reputation:**189,771

Scirra Founder

B

382
S

223
G

86
If you use random usually you want equal weighting, i.e. each number is as likely as any other to come up. For example:

int(random(2)) will give:

0 (50% of the time)

1 (50% of the time)

Note both have an equal chance of appearing.

round(random(2)) will give:

0 (25% of the time)

1 (50% of the time)

2 (25% of the time)

Not only is the range different, but different numbers have different chances of appearing. In the long run you'll get twice as many 1's as you probably expected. Like I say, usually you want all numbers to appear roughly as many times as each other in the long run, so int() or floor() are probably better here.

int(random(2)) will give:

0 (50% of the time)

1 (50% of the time)

Note both have an equal chance of appearing.

round(random(2)) will give:

0 (25% of the time)

1 (50% of the time)

2 (25% of the time)

Not only is the range different, but different numbers have different chances of appearing. In the long run you'll get twice as many 1's as you probably expected. Like I say, usually you want all numbers to appear roughly as many times as each other in the long run, so int() or floor() are probably better here.

**Posts:**23,997**Reputation:**189,771

Scirra Founder

B

382
S

223
G

86
**Posts:**19**Reputation:**3,204

B

16
S

3
G

6
11 posts
• Page **1** of **2** • **1**, 2

## Who is online |

Users browsing this forum: Digitalarray and 4 guests |