TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Michael Malcolm
NA
5
1.4k
Random Array of numbers
Sep 5 2011 11:25 AM
Hi there, I would like to figure out how to shorten a piece of code.
I have it working the way I want it to work however I know it can be simplified, I just can't figure out how.
I want to make a do while loop that checks to see if the array is empty.
int draw;
int[] balls = new int[5];
int size = balls.Length;
int count = 0;
Random rdmn = new Random();
for (int i = 0; i < size; i++)
{
draw = rdmn.Next(50);
if (!balls.Contains(draw))
{
balls[count] = draw;
count++;
}
else
{
size++;
}
}
foreach (int n in balls)
{
Console.WriteLine(n);
}
Right now I am adding to the size of the loop if the number is not unique. However if I can put in a do while loop then I can get rid of int size, etc.
Thank for your time.
Reply
Answers (
4
)
Access computer in another domain through WMI
How to fix update error?