DNX Core 5.0 library to target any platform. No System.Random class. Workarounds or options?

2.2k views Asked by At

I am trying out the Visual Studio 2015 RC project template for creating a class library

that can target any platform

says Visual Studio.

A new project has 2 references: DNX 4.5.1 and DNX Core 5.0. It appears that System.Random is not available in DNX Core 5.0. (The same is true for the .NET Core 5.0 Console project template.)

For .NET Core libraries/apps, what options are there for generating random numbers?


To truly target any platform, I guess one could implement a pseudorandom number generator, or wait until a DNX Core-compatible reference is available, that has someone else implement a PRNG. Microsoft could be that someone by the time 2015 is no longer "RC".

2

There are 2 answers

4
Ufuk Hacıoğulları On BEST ANSWER

I think it's included in System.Runtime.Extensions package. Add it to dependencies and run dnu restore if you are building from the command line. Then it should build.

0
codeReview On

Look at Microsoft's System.Random source code

See if a copy & paste will compile.

If you don't intend to generate lots of instances of PRNGs, then DateTime.Now.Ticks is supported by DNX 5.0 and could be used as the seed.