-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Numerics
Milestone
Description
Background and motivation
Now that we have the generic math interfaces, we should be able to write a method for generating a random value that can work with any T where T implements the appropriate interface.
API Proposal
namespace System;
public class Random
{
public T Next<T>() where T : INumber<T>;
public T Next<T>(T maxValue) where T : INumber<T>;
public T Next<T>(T minValue, T maxValue) where T : INumber<T>;
}API Usage
Random r = new Random();
Int128 value = r.Next<Int128>();Alternative Designs
- We might need two sets of methods, one for integral values and one for floating-point values. In that case,
INumber<T>isn't the right interface; each set will use its own that appropriate. - The range used for NextDouble is 0.0 to 1.0; for a floating-point API, we'd presumably want to map to the same range?
Risks
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Numerics