Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Randomly Initializing array with class Objects
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Krocker




PostPosted: 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
Sponsor
sponsor
Raknarg




PostPosted: 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




PostPosted: 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




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: