• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

Random number with an existing list using C Sharp

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
BobRosas
Asked:
BobRosas
2 Solutions
 
käµfm³d 👽Commented:
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
 
MisbahCommented:
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
 
BobRosasAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now