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

Username:   Password: 
 RegisterRegister   
 help - stop random number from repeating
Index -> Programming, Java -> Java Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
whoareyou




PostPosted: Mon Jun 13, 2011 7:31 pm   Post subject: RE:help - stop random number from repeating

YAY! I was right (H) Very Happy
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Jun 13, 2011 7:43 pm   Post subject: RE:help - stop random number from repeating

Except that you don't get an even distribution with this method. That is, some outcomes of this type of a shuffle are more likely than others (ideally they should all be the same). See http://www.codinghorror.com/blog/2007/12/the-danger-of-naivete.html for a detailed explanation of what is going on.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
RandomLetters




PostPosted: Mon Jun 13, 2011 8:34 pm   Post subject: Re: help - stop random number from repeating

whoareyou @ Mon Jun 13, 2011 7:24 pm wrote:
This is the code I'm using from this examplesdepot website:

code:

// Create a list
List list = new ArrayList();

// Add elements to list

// Shuffle the elements in the list
Collections.shuffle(list);

// Create an array
String[] array = new String[]{"a", "b", "c"};

// Shuffle the elements in the array
Collections.shuffle(Arrays.asList(array));


So in order to use ArrayList, I importt java.util.*, then it says, "Type List is imported on demand from java/awt and java/util.".
Then I changed the import to java.util.ArrayList, then it says "you cannot assign a "java.util.ArrayList" expression to a "java.awt.List" variable."

Neutral


That's because the awt package has its own List class. Try importing the specific classes that you need from each package. Or http://download.oracle.com/javase/tutorial/java/package/usepkgs.html near the bottom if you actually need to use both.
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 2 of 2  [ 18 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: