Random
The WASI random number generation interfaces allows WebAssembly code to generate random numbers.
FastRandomSource​
Generates pseudo random numbers using System.Random
.
FastRandomSource
accepts a seed
value in the constructor, supplying the same seed will produce exactly the same sequence of random numbers. This can be used to ensure WASM execution is deterministic.
System.Random
is not cryptographically secure. Do not use FastRandomSource
for a WASM container which does any cryptography.
CryptoRandomSource​
Generates pseudo random numbers using System.Security.RandomNumberGenerator
.
System.Security.RandomNumberGenerator
is approximately 50x slower than System.Random
.
IVirtualRandomSource​
The base interface for all WASI RNG implementations. If the default RNGs do not fit your use-case custom implementations can be built using this interface
WasiError RandomGet(Caller caller, Buffer<byte> output)
​
Fill Buffer
with random data and return WasiError.SUCCESS
to indicate success.
void Register(Linker linker)
​
Add all functions of this implementation to the Linker. This can usually be implemented as a direct call to linker.Register(this);
.