FsRandom
FsRandom is a purely-functional random number generator framework designed for F# language. It helps you to obtain a variety of random numbers to use more than ten predefined generators, and to define a new function to generate random numbers you want.
How to Install
Install from NuGet
FsRandom is available on the NuGet Gallery.
Run in the Package Manager Console:
PM> Install-Package FsRandom
Build from source code
FAKE script is included in the source code.
To make a debug build, run:
> fsi tools\build.fsx --debug
Short Example
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: |
|
The script yields:
|
Features
Random Functions
FsRandom provides a variety of random number generator functions:
-
RandomNumberGenerator module provides standard random number generators:
``(0, 1)``
,``[0, 1)``
,``(0, 1]``
, and``[0, 1]``
. - Random module manipulates random numbers.
- Statistics module provides a variety of statistical distributions such like
uniform
,normal
andgamma
. - Seq module provides functions for generating random number sequences.
- Array module and Array2D module provide functions for array operations like
createRandom
,sample
,sampleWithReplacement
, andshuffle
. - List module provides functions for generating random lists.
- String module provides functions for generating random strings.
- Utility module provides utility functions.
Pseudo-Random Number Generators
You can choose an algorithm of pseudo-random numbger generator:
- xorshift implements Xorshift algorithm.
- systemrandom leverages System.Random and its subclasses as a random number generators. This PRNG is not purely functional because the state of the PRNG is controled in the classes.
- mersenne in MersenneTwister module implements 64-bit version of Mersenne Twister algorithm.
- sfmt in SimdOrientedFastMersenneTwister module implements SFMT algorithm.
namespace FsRandom
val state : PrngState
Full name: Index.state
Full name: Index.state
val createState : prng:Prng<'s> -> seed:'s -> PrngState
Full name: FsRandom.RandomNumberGenerator.createState
Full name: FsRandom.RandomNumberGenerator.createState
val xorshift : Prng<uint32 * uint32 * uint32 * uint32>
Full name: FsRandom.RandomNumberGenerator.xorshift
Full name: FsRandom.RandomNumberGenerator.xorshift
val randomPointGenerator : GeneratorFunction<float * float>
Full name: Index.randomPointGenerator
Full name: Index.randomPointGenerator
val random : RandomBuilder
Full name: FsRandom.RandomNumberGenerator.random
Full name: FsRandom.RandomNumberGenerator.random
val x : float
val ( [0, 1) ) : GeneratorFunction<float>
Full name: FsRandom.RandomNumberGenerator.( [0, 1) )
Full name: FsRandom.RandomNumberGenerator.( [0, 1) )
val y : float
module Statistics
from FsRandom
from FsRandom
val normal : mean:float * standardDeviation:float -> GeneratorFunction<float>
Full name: FsRandom.Statistics.normal
Full name: FsRandom.Statistics.normal
val randomPoint : float * float
Full name: Index.randomPoint
Full name: Index.randomPoint
module Random
from FsRandom
from FsRandom
val get : generator:GeneratorFunction<'a> -> PrngState -> 'a
Full name: FsRandom.Random.get
Full name: FsRandom.Random.get
val printf : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printf
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printf