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

**Posts:**23,448**Reputation:**186,086

Scirra Founder

B

373
S

218
G

84
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,448**Reputation:**186,086

Scirra Founder

B

373
S

218
G

84
**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: DankP3, shinichild and 6 guests |