• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • 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?

2 Solutions
käµfm³d 👽Commented:
   random = new random between 0 and upper bound (index) of list
while list[random].Active != True

acct = list[random]

Open in new window

you need to write code similar to the one below:
Customer[] list = ....
Random r = new Random(list.Length-1);
Customer random = list[r.next];
random = list[r.next];


Open in new window

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!
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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