Implementing a custom pseudo-random number generator
In many situations in Julia, you might want to extend some abstract type defined in the base language. In this recipe, we will show how you can implement a simple pseudo-random number generator extending AbstractRNG
.
Getting ready
In order to create your own pseudo-random number generator, you have to define a concrete type that is a subtype of the AbstractRNG
abstract type and which implements methods for the seed!
, rand
, and rng_native_52
functions. In this recipe, we will show how you can achieve this.
The generator we will implement is called 64-bit Xorshift. It was proposed by George Marsaglia in the paper, Xorshift RNGs, published in the Journal of Statistical Software, Vol 8(2003), Issue 14.
Before running this recipe, make sure that you have the StatsBase.jl
and BenchmarkTools.jl
packages installed. If it is missing make sure that you have it by running the following commands:
julia> using Pkg julia> Pkg.add("BenchmarkTools"...