-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix Random* Int64 overloads: Use Trunc
- Loading branch information
Showing
12 changed files
with
154 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
############## | ||
Random Numbers | ||
############## | ||
|
||
Simba provides various methods to generate random numbers with different distributions. | ||
|
||
The following methods are: | ||
|
||
Random: | ||
""""""" | ||
|
||
Random generates approximately uniform distribution. | ||
|
||
.. code-block:: | ||
function Random: Double; overload; | ||
function Random(l: Int64): Int64; overload; | ||
function Random(min, max: Double): Double; overload; | ||
function Random(min, max: Int64): Int64; overload; | ||
----- | ||
|
||
RandomLeft: | ||
""""""""""" | ||
|
||
RandomLeft generates weighted numbers towards :code:`Lo` | ||
|
||
.. code-block:: | ||
function RandomLeft(Lo, Hi: Double): Double; overload; | ||
function RandomLeft(Lo, Hi: Int64): Int64; overload; | ||
----- | ||
|
||
RandomRight: | ||
"""""""""""" | ||
|
||
RandomRight generates weighted numbers towards :code:`Hi` | ||
|
||
.. code-block:: | ||
function RandomRight(Lo, Hi: Double): Double; overload; | ||
function RandomRight(Lo, Hi: Int64): Int64; overload; | ||
----- | ||
|
||
RandomMean: | ||
""""""""""" | ||
|
||
RandomMean generates weighted numbers towards the mean of :code:`Lo..Hi` | ||
|
||
.. code-block:: | ||
function RandomMean(Lo, Hi: Double): Double; overload; | ||
function RandomMean(Lo, Hi: Int64): Int64; overload; | ||
----- | ||
|
||
RandomMode: | ||
""""""""""" | ||
|
||
RandomMode generates weighted numbers towards :code:`Mode` within :code:`Lo..Hi` | ||
|
||
.. code-block:: | ||
function RandomMode(Mode, Lo, Hi: Double): Double; overload; | ||
function RandomMode(Mode, Lo, Hi: Int64): Int64; overload; | ||
----- | ||
|
||
| You can also write a small script to show the spread. | ||
| This shows the spread of 1000000 calls of :code:`RandomLeft(0, 10)`: | ||
.. code-block:: | ||
const | ||
SampleCount = 1000000; | ||
Range = 10; | ||
var | ||
Hits: TIntegerArray; | ||
I: Integer; | ||
begin | ||
SetLength(Hits, Range); | ||
for I := 1 to SampleCount do | ||
Hits[RandomLeft(0, Range)] += 1; | ||
for I := 0 to High(Hits) do | ||
WriteLn(I, ' was rolled ', Hits[I], ' times (', Round((Hits[I] / SampleCount) * 100, 4), ' percent)'); | ||
end; | ||
Output | ||
|
||
.. code-block:: none | ||
0 was rolled 382874 times (38.2874 percent) | ||
1 was rolled 300305 times (30.0305 percent) | ||
2 was rolled 183102 times (18.3102 percent) | ||
3 was rolled 88345 times (8.8345 percent) | ||
4 was rolled 32958 times (3.2958 percent) | ||
5 was rolled 9715 times (0.9715 percent) | ||
6 was rolled 2195 times (0.2195 percent) | ||
7 was rolled 442 times (0.0442 percent) | ||
8 was rolled 60 times (0.006 percent) | ||
9 was rolled 4 times (0.0004 percent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ Tutorials | |
|
||
.. toctree:: | ||
|
||
Random Numbers.rst | ||
Color Finding.rst | ||
Sleep Until.rst | ||
Input & Finder Target.rst | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const | ||
SampleCount = 1000000; | ||
Range = 10; | ||
|
||
var | ||
Hits: TIntegerArray; | ||
I: Integer; | ||
begin | ||
SetLength(Hits, Range); | ||
for I := 1 to SampleCount do | ||
Hits[RandomLeft(0, Range)] += 1; | ||
|
||
for I := 0 to High(Hits) do | ||
WriteLn(I, ' was rolled ', Hits[I], ' times (', Round((Hits[I] / SampleCount) * 100, 4), ' percent)'); | ||
end; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters