View Single Post
Old Apr 29th, 2008, 2:45 PM   #5
Freaky Chris
Hobbyist Programmer
 
Freaky Chris's Avatar
 
Join Date: Dec 2007
Location: England
Posts: 169
Rep Power: 1 Freaky Chris is on a distinguished road
Send a message via MSN to Freaky Chris
Re: populate array with random nonrepeating #'s

Quote:
Originally Posted by Alias View Post
You want to fill an array with a length of fourty-two, with numbers one to fourty-two and further yet the numbers should be at random points in the array, right?

If I got that right, why not just fill the array with values one through to fourty-two and manually shuffle the array?
Indeed this is a good way of looking at doing this, it would sure that you do notn have duplicates, and you could simple use a random number to access different slots of the array. Using the same technique to ensure that you do not choose the same slot.

But working with what you have, you may find that the reason you have a 0 at the end is simple you have declared and array of size 43 instead of 42, not sure on that but quite often that is the reason behind it.

Alias, just added a method Using ArrayLists or Vectors, not sure if C# uses arraylists im sure he will clarify which it is, which does indeed make things simpler for you.

Chris
__________________
Who said i couldn't program
sarcasm = raw_input('Type in a sarcastic remark: ')
print sarcasm
Freaky Chris is offline   Reply With Quote