Example for Mir-Random fails
Brad
bjazmoore at outlook.com
Sat Apr 3 19:02:34 UTC 2021
I just do not know enough about the D libraries to figure out
what is wrong. I know it is a case of type mismatch. The
example appears on the Mir-Random page as listed under DUB:
https://code.dlang.org/packages/mir-random
The code looks like this:
```d
void main()
{
import mir.random;
import mir.random.variable: normalVar;
import mir.random.algorithm: randomSlice;
// Engines are allocated on stack or global
auto rng = Random(unpredictableSeed);
auto sample = rng.randomSlice(normalVar, 10);
import std.stdio;
sample[rng.randIndex($)].writeln;
}
```
This is the error I am seeing (I slapped the sample code into
another program that flips a coin... It compiles file without the
sample code):
```d
source\flipcoin.d(39,20): Error: constructor
`std.random.MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU,
31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU,
4022730752u, 18LU, 1812433253u).MersenneTwisterEngine.this(uint
value)` is not callable using argument types `(ulong)`
source\flipcoin.d(39,20): cannot pass argument
`unpredictableSeed()` of type `ulong` to parameter `uint value`
```
Obviously it is a type mismatch - I have tried using to!uint to
convert the result from unpredictableSeed to a type that will
match - but that just causes more errors.
Thank you in advance.
More information about the Digitalmars-d-learn
mailing list