File tree 4 files changed +22
-0
lines changed
4 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -261,6 +261,14 @@ Works without any arguments.
261
261
x = rand() // any number between 0 and 1
262
262
```
263
263
264
+ ### Generate Single Random Integer
265
+
266
+ Works with one argument.
267
+
268
+ ```
269
+ x = randi(5) // any integer between 0 and 5
270
+ ```
271
+
264
272
### Generate Random Vector
265
273
266
274
Works with one argument.
Original file line number Diff line number Diff line change @@ -27,6 +27,12 @@ public static Double GetNumber()
27
27
return _random . NextDouble ( ) ;
28
28
}
29
29
30
+ public static Int32 GetInteger ( Int32 maximum )
31
+ {
32
+ EnsureRandom ( ) ;
33
+ return ( Int32 ) Math . Round ( _random . NextDouble ( ) * maximum ) ;
34
+ }
35
+
30
36
private static Double [ , ] CreateMatrix ( Int32 rows , Int32 cols )
31
37
{
32
38
var matrix = new Double [ rows , cols ] ;
Original file line number Diff line number Diff line change @@ -686,6 +686,13 @@ public static class StandardFunctions
686
686
( args . Length > 0 ? If . Is < Double > ( args , SimpleRandom . CreateVector ) : null ) ??
687
687
SimpleRandom . GetNumber ( ) ) ;
688
688
689
+ /// <summary>
690
+ /// Contains the random integer function.
691
+ /// </summary>
692
+ public static readonly Function Randi = new ( args => Curry . MinOne ( Randi , args ) ??
693
+ If . Is < Double > ( args , x => SimpleRandom . GetInteger ( ( int ) x ) ) ??
694
+ 0 ) ;
695
+
689
696
/// <summary>
690
697
/// Contains the throw function.
691
698
/// </summary>
Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ static class Global
41
41
{ "gamma" , StandardFunctions . Gamma } ,
42
42
{ "sqrt" , StandardFunctions . Sqrt } ,
43
43
{ "rand" , StandardFunctions . Rand } ,
44
+ { "randi" , StandardFunctions . Randi } ,
44
45
{ "sin" , StandardFunctions . Sin } ,
45
46
{ "cos" , StandardFunctions . Cos } ,
46
47
{ "tan" , StandardFunctions . Tan } ,
You can’t perform that action at this time.
0 commit comments