473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

checkNonDuplicates

mia023
89
if we randomly generate Complex numbers how can we check if these numbers are duplicate or not??
Dec 30 '07 #1
6 1308
BigDaddyLH
1,216 Expert 1GB
if we randomly generate Complex numbers how can we check if these numbers are duplicate or not??
By comparing them in some way, or generating them in a fashion that precludes duplication.

What are you trying to do? What is your goal?
Dec 31 '07 #2
dmjpro
2,476 2GB
if we randomly generate Complex numbers how can we check if these numbers are duplicate or not??
I think when you are generating Random number then Random numbers API ensures that no duplicate numbers will be generated.

Debasis Jana
Dec 31 '07 #3
chaarmann
785 Expert 512MB
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.getCurrentTimeMillis() 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.
Dec 31 '07 #4
mia023
89
Here is the way that I thought of it:

public static boolean check_NonDuplicate(Complex c[]){
c=new Complex[c.length];
for(int i=0;i<c.length;i++){
if((c[0].getReal()!=c[i].getReal()||c[0].getImag()!=c[i].getImag()))
return false;

}
return true;
}
Dec 31 '07 #5
JosAH
11,448 Expert 8TB
I think when you are generating Random number then Random numbers API ensures that no duplicate numbers will be generated.

Debasis Jana
*ahem* did you actually *read* the API documentation of the Random class?

kind regards,

Jos
Dec 31 '07 #6
dmjpro
2,476 2GB
*ahem* did you actually *read* the API documentation of the Random class?

kind regards,

Jos
Sorry :-(

Debasis Jana
Dec 31 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
mia023
by: mia023 | last post by:
how can i check if the elements in an array exist twice
1
mia023
by: mia023 | last post by:
Does the random class checks if the numbers are duplicate or not with out me implementing the algorithm for checking if duplicate?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.