Reputation: 199
i need algorithm for generate random complex number please help i know how generate random number but random complex number confuse me
Upvotes: 2
Views: 4262
Reputation: 393
1.Generate 2 vector of numbers say one is real_vector and another is imaginary_vector of size say MAX_SIZE to be generated randomly with differrent seeds.
2.Random shuffle the numbers in vectors(real_vector+imaginary_vector) using any distribution let us say use of std::random_shuffle(uniform distribution).
3.randomly generate a index and apply modulo operator for MAX_SIZE and select index from first array that will provide an real part of ur random number.
4.use step 3 to get imaginary part of your random number.
5.Create a complex number using number got from step 3 and step 4 and store in a container.
6.go to step 3 and check if you want any more complex number;if no then break;
Upvotes: 0
Reputation: 331
I would simply generate two random numbers and use one for the real part and one for the imaginary part.
Upvotes: 8
Reputation: 300539
Generate 2 random numbers (x, y) (use the built-in rand/rnd/random class from your environment's libraries), where x
is the real part and y
is the imaginary part.
Create a complex number class (with a constructor that takes a real and imaginary parameter)
Use the 2 random numbers from step 1 to create a complex number, x + i y
Upvotes: 5