T. Webster
T. Webster

Reputation: 10109

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

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".

Upvotes: 1

Views: 2211

Answers (2)

Ufuk Hacıoğulları
Ufuk Hacıoğulları

Reputation: 38478

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.

Upvotes: 6

codeReview
codeReview

Reputation: 175

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.

Upvotes: 3

Related Questions