www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17832] New: std.random.choice cannot be used with other

https://issues.dlang.org/show_bug.cgi?id=17832

          Issue ID: 17832
           Summary: std.random.choice cannot be used with other random
                    generators
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: fediushin.anton yandex.ru

This code:
```
auto arr = [1,2,3];
choice(arr);

auto rng = Random();
choice(arr, rng);

auto rng2 = Xorshift();
choice(arr, rng2);
```

Fails on the last line with:
/usr/include/dlang/dmd/std/random.d(2002): Error: cannot implicitly convert
expression rndGen() of type MersenneTwisterEngine!(uint, 32LU, 624LU, 397LU,
31LU, 2567483615u, 11LU, 4294967295u, 7LU, 2636928640u, 15LU, 4022730752u,
18LU, 1812433253u) to XorshiftEngine!(uint, 128u, 11u, 8u, 19u)
randomissue.d(11): Error: template instance std.random.choice!(int[],
XorshiftEngine!(uint, 128u, 11u, 8u, 19u)) error instantiating

--
Sep 17 2017