Author |
Message |
Krocker
|
Posted: Mon Feb 03, 2014 12:45 pm Post subject: Randomly Initializing array with class Objects |
|
|
Hi, i was wondering how would i go about initializing an array with objects randomly. So i have a random number generator that generates an int between 1 and 3. If the int is 1, then the array[ i ] = the object 1 and if the int is 2 then array[i] = object 2. I have no idea how i would do this in the least amount of codes. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Raknarg
|
Posted: Mon Feb 03, 2014 4:36 pm Post subject: RE:Randomly Initializing array with class Objects |
|
|
What kind of objects are they? If they are similar enough, you can probably use interfaces, or possibly inheritance. |
|
|
|
|
|
DemonWasp
|
Posted: Mon Feb 03, 2014 5:34 pm Post subject: RE:Randomly Initializing array with class Objects |
|
|
It seems like you want to shuffle object order in an array. Figure out a way to shuffle integers (there are many examples on this forum). You should be able to figure out how to switch that to moving objects (or references to objects) rather than integers. |
|
|
|
|
|
Raknarg
|
Posted: Mon Feb 03, 2014 7:54 pm Post subject: RE:Randomly Initializing array with class Objects |
|
|
Oh. I assumed he meant mixing different objects in the same array. |
|
|
|
|
|
|