if we randomly generate Complex numbers how can we check if these numbers are duplicate or not??
checkNonDuplicates
Collapse
X
-
By comparing them in some way, or generating them in a fashion that precludes duplication.Originally posted by mia023if we randomly generate Complex numbers how can we check if these numbers are duplicate or not??
What are you trying to do? What is your goal? -
I think when you are generating Random number then Random numbers API ensures that no duplicate numbers will be generated.Originally posted by mia023if we randomly generate Complex numbers how can we check if these numbers are duplicate or not??
Debasis JanaComment
-
if no duplicates occur, then it's not "random" anymore.
if you want to have a sequence of numbers that "look random", but without duplicates, then you can use the System.getCurre ntTimeMillis() function. (always wait for a random number of milliseconds before getting the next number in sequence). Then you can cut off the highest digits and shuffle them if needed.
Otherwise, to sort out the duplicates in an array that already contains random generated numbers, you have to compare the last number in array against all the others and delete if it already exists, then the second last against all the others and so on. (like bubble sort).
or you use a Binary Tree for better performance: put the first in, then the second if the second is not already inside, then the third if it is not already inside and so on.Comment
-
*ahem* did you actually *read* the API documentation of the Random class?Originally posted by dmjproI think when you are generating Random number then Random numbers API ensures that no duplicate numbers will be generated.
Debasis Jana
kind regards,
JosComment
Comment