?
Solved

Random number with an existing list using C Sharp

Posted on 2011-03-17
3
Medium Priority
?
288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 200 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 200 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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!
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

770 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