![]() |
populate array with random nonrepeating #'s
I am trying to fill an array with random #'s from 1 to 42 using every number in the range exactly once. here is what I have:
:
|
Re: populate array with random nonrepeating #'s
Should it not just be as simple as checking storing the last number to be generated and stored, then checking it agaisnt the new number to see if it is the same if it is then generate a new number?
Sorry, re-read you may want to store each randomly generated number in an array then check each new number against those in the array. im confusing myself lol Chris |
Re: populate array with random nonrepeating #'s
thank u...storing the random numbers in an array first seemed to do what i needed, however i am still getting a 0 printed at the end of my list. Any ideas on why i get this and how to get rid of it?
|
Re: populate array with random nonrepeating #'s
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? Anyway, continuing with your own technique, this ought to help: :
|
Re: populate array with random nonrepeating #'s
Quote:
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 |
Re: populate array with random nonrepeating #'s
If you add the following classes to your project, you can populate a list like this:
:
Series.cs :
RandomizedSeries.cs :
|
Re: populate array with random nonrepeating #'s
i got it working but your code was much more concise alias. I might replace mine anyway. Thank you guys for your help.
|
Re: populate array with random nonrepeating #'s
i was thinking about this today and realized that it would make sense to randomize any enumerable. thus:
RandomEnumerable.cs :
p.s. this forum sure sucks at highlighting c# |
Re: populate array with random nonrepeating #'s
i suck at writing enumerables... i tried to use mine in a different program and found they needed to be modified. here they are:
Series.cs :
RandomEnumerable.cs :
|
Re: populate array with random nonrepeating #'s
mbd, thats alot of work to do nothing.
|
| All times are GMT -5. The time now is 9:43 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC