std.random.uniform failing

remontoir marc.p.michel at gmail.com
Tue Sep 3 11:57:42 UTC 2024


Not really sure what is happening here.
This works is "None" is removed, but displays a silly answer or 
fails with "range is smaller than amount of items to pop" 
otherwise.

I guess it is related to enum being also integers ?

```d
import std.stdio : write, writeln;
import std.random;
import std.algorithm.mutation : remove;

enum Axis { None, X, Y, Z }

void main() {
     Axis[] axes = [Axis.X, Axis.Y, Axis.Z];
     writeln("Original array: ", axes);

     auto axis = axes[uniform(0, axes.length)];
     writeln(axis);
     axes = axes.remove(axis);
     writeln("Array after removing ", axis, " : ", axes);
}

```



More information about the Digitalmars-d-learn mailing list