|
||||||
| C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
| Sponsored Links |
|
|
|
|||
|
Code:
private int[] PopulateRandomNumbers(int arraylength, int minvalue, int maxvalue)
{
DateTime c = DateTime.Now;
Random r = new Random(c.Millisecond);
int[] RandomNumbers = new int[arraylength];
int RandomNumber;
for (int i = 0; i < arraylength; i++)
{
RandomNumber = r.Next(minvalue, maxvalue);
while (isExistIn(RandomNumber, RandomNumbers) == true)
{
RandomNumber = r.Next(minvalue, maxvalue);
}
RandomNumbers[i] = RandomNumber;
}
return RandomNumbers;
}
private Boolean isExistIn(int number, int[] Numbers)
{
Boolean result = false;
for (int i = 0; i < Numbers.Length; i++)
{
if (Numbers[i] == number)
{
result = true;
}
}
return result;
}
Code:
int[] RN = PopulateRandomNumbers(40, 1, 42);
__________________
Information Technology Talk |
|
|||||
|
It's not completely necessary to instantiate so many objects, but this makes it clearer to read/understand. Good help, though. +rep given.
Welcome to CodeCall anyhow, excavator! |
|
|||
|
@Xav
I agree, and thanks. ![]() @gaylo565 glad i can be of support ![]()
__________________
Information Technology Talk |
| Sponsored Links |
|
|
|
|||||
|
You're welcome. Not many people use the reputation system, so we try to encourage it as much as possible!
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Encryption using Random!? | TcM | Programming Theory | 14 | 01-07-2008 10:48 AM |
| Random Elements From Array | Victor | Java Help | 8 | 12-01-2007 09:38 PM |
| HELP! 3x3 array random number 1-9 no repeat | siren | C and C++ | 3 | 09-25-2007 02:03 PM |
| Return random numbers without duplicates | Paradine | PHP Tutorials | 0 | 08-26-2007 02:07 PM |
| Python 2D array question | annannienann | Python | 3 | 04-23-2007 04:36 PM |