C # Creating random decimal between two decimal places

EDIT I will explain when I say decimal, I mean system.decimal not a mathematical concept

 decimal min = 5.62; decimal max = 14.39; 

How do I get system.decimal , which is randomly between the range of the two previous commas?

Double! = System.decimal

FYI I don’t know how I can make my question clearer, since more than half of the people who read this only read 2 words and then are marked as duplicate.

+4
source share
4 answers

y = x + s. Create 0 <= X <1 FP random with NextDouble (), multiply it by (Dmax-Dmin) in the right range, then add Dmin to offset the base.

+4
source

Scale your decimal numbers for int or large ints (by multiplying by the corresponding power of 10. Create an int between them, then divide by 10.

Or generate an int, and then just scale it (linearly) between decimals.

+3
source

Here is a resource right here on StackOverflow;)

Creating a random decimal in C #

or you can try:

 Random random = new Random(); Math.Round((random.NextDouble() / 100),3)); 

Hope this helps!

+1
source
 public static double randomDouble(Random rand, double start, double end) { return (rand.NextDouble() * Math.Abs(end-start)) + start; } 
0
source

Source: https://habr.com/ru/post/1393208/


All Articles