Picomite/PicoMiteVGA V5.07.05 release candidates


Author Message
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3811
Posted: 01:48pm 03 Nov 2022      

@Peter,

When you find time, can you please explain how the index in an array is calculated.
The index is an integer, but it is not calculated using the INT(x) function in case X is a FLOAT ?

Example:
random dice rolls can be calculated using 1+RND()*6
if I use these as index in a array (1,000,000 rolls) I get following distribution


Option default integer
Dim distribution(7)

For i=1 To 1e6
 Inc distribution(1+Rnd*6),1
Next i

For i=0 To 7
 Print i, distribution(i)
Next i
End

0       0
1       83119
2       166639
3       166889
4       166590
5       166382
6       166897
7       83484


Only when I explicitly use the INT(x) function I get a correct distribution.

Dim distribution(7)

For i=1 To 1e6
 Inc distribution(Int(1+Rnd*6)),1
Next i

For i=0 To 7
 Print i, distribution(i)
Next i
End

0       0
1       166619
2       166640
3       166988
4       166171
5       166966
6       166616
7       0