Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day everyone. i am developing an application that will randomly distribute an inputed number into 4 different places and when the distributed numbers are added it will sum up to the inputed numbers. THanks.

What I have tried:

private int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max); 
}
Posted
Updated 27-Dec-17 19:47pm
Comments
vivvicks 27-Dec-17 22:54pm    
what exact logic u are trying to build?
Karthik_Mahalingam 27-Dec-17 23:28pm    
what is your input and expected output?

1 solution

For starters, don't do it like that: each time you call that method, it creates a new random number and seeds it from the system clock. Unless you have a very slow processor, that means that if you call that method several times in quick succession, you will get the same random number sequence from each - which is not random!
Move the Random instance outside the method and it should start to work better:
C#
private Random random = new Random();
private int RandomNumber(int min, int max)
    {
    return random.Next(min, max); 
    }

If that doesn't fix your problem, you will have to explain in much better detail exactly what you are trying to do - your description is very vague and brief, and we cannot work out from that little what you are trying to do. Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
 
Share this answer
 

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