Solved

Random number with an existing list using C Sharp

Posted on 2011-03-17
3
285 Views
Last Modified: 2012-05-11
I need C# code that will select a random customer account number.  The problem is I do not want the customer number selected if they are not active.  How do I choose a random number from a generated list?

0
Comment
Question by:BobRosas
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 50 total points
ID: 35161297
Psedocode:
do
   random = new random between 0 and upper bound (index) of list
while list[random].Active != True

acct = list[random]

Open in new window

0
 
LVL 9

Assisted Solution

by:Misbah
Misbah earned 50 total points
ID: 35161310
you need to write code similar to the one below:
Customer[] list = ....
Random r = new Random(list.Length-1);
Customer random = list[r.next];
while(!random.IsActive)
{
random = list[r.next];

}

Open in new window

0
 

Author Comment

by:BobRosas
ID: 35161354
I'm having other issues so I won't be able to test this yet.  I've doubled points and awarded you both for your help.  I'll post related questions if needed.
Thanks so much!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question