Ticket #35822

The random function doesn't often include the highest number

Date d'ouverture: 2015-12-08 21:13 Dernière mise à jour: 2016-02-09 21:18

Rapporteur:
Propriétaire:
Type:
État:
Atteints
Composant:
Priorité:
5 - moyen
Sévérité:
6
Résolution:
Fixed
Fichier:
1
Vote
Score: 0
No votes
0.0% (0/0)
0.0% (0/0)

Détails

The foillowing command:

random Val 10

Should assign the variable "Val" with a random number from 0 to 10. However, testing this function, the random numb is evenly distributed from 0 to 9, and only very rarely is 10. Using 10 is just an example, using other values, the highest expected value is hardly ever there. Using version 4.89 and the command above, the distribution obtained from 1,000,000 calls was:

0	100427
1	100153
2	100098
3	100297
4	99515
5	100237
6	99801
7	99904
8	99822
9	99713
10	34

Ticket History (3/8 Histories)

2015-12-08 21:13 Updated by: alandamore
  • New Ticket "The random function doesn't often include the highest number" created
2015-12-08 21:30 Updated by: doda
  • Propriétaire Update from (Aucun) to doda
  • Résolution Update from Aucun to Accepted
2015-12-08 22:13 Updated by: (del#1144)
Commentaire

http://xyzan-02.blog.so-net.ne.jp/2012-04-20

今の実装だと、ちょうど 1.0 になるときだけ<max number>が返るようですね。1,000,000/32768≒30.51なので、確率的にもこれで正しいと思います。

2015-12-09 01:37 Updated by: doda
Commentaire

この件に関しては計算式の間違いが原因なのでそれを直せばいいのですが、 別件(#35823 #35824)の事を考えて実装を変えようと思っています。

2015-12-10 01:41 Updated by: doda
  • Résolution Update from Accepted to Fixed
Commentaire

This issue fixed on next release.

Thanks.

2015-12-10 12:17 Updated by: (del#1144)
Commentaire
2016-02-09 21:18 Updated by: (del#1144)
  • État Update from Ouvert to Atteints
  • Ticket Close date is changed to 2016-02-09 21:18

Attachment File List

Modifier

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Connexion