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

**Posts:**25,207**Reputation:**200,355

Scirra Founder

B

414
S

245
G

92
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:**25,207**Reputation:**200,355

Scirra Founder

B

414
S

245
G

92
**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: Zed2100 and 3 guests |