Click here to Skip to main content
15,907,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hiii,

one textbox is there and in which i have to enter the value(lyk i enter 1500) and i have to generate i 1000 random value in gridview and this values are in between .01 to 3.0. and this values total is equal to 1500 which we enter so how can i do or provide me code to generate random value in between the range that i above mention thank you.....
Posted
Updated 24-Sep-14 18:04pm
v2

1 solution

try this code:

C#
public static IEnumerable<int> GetRandom()
{
    var rand = new Random();
    while (true)
    {
        yield return
        rand.Next(.01, 3);
    }
}

public static List<int> GetThirtyThatAddToTwoHundred()
{
    do
    {
        var current = GetRandom().Take(1000);
        if (1500 == current.Sum())
        {
            return current.ToList();
        }
    } while (true);
}


**taken from StackOverFLow **
 
Share this answer
 
Comments
MuhammadUSman1 25-Sep-14 1:12am    
We can't add float value in rand.Next(.01,3);
So how we add float/decimal with point value in your solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900