# get prime numbers in a random sequence using bit shift operators

how to generate prime numbers in a random sequence  using bitwise operators
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
What do you mean by "in random sequence" ? Why using bitwise operators ?

What is this for ?

Do you want prime numbers within a certain range ? Or just any prime numbers ?
0
Author Commented:
i mean prime numbers in a range

how to generate prime numbers with in a certain range using bit operators ?
this was the question asked to me in an interview
0
Senior Software Engineer (Avast)Commented:
I'm not sure there is enough info in the Q to provide and effective or useful answer.
0
Commented:
I've got the same impression that there's something missing ... What's the relation between prime numbers and bitwise operations ?
0
Senior Software Engineer (Avast)Commented:
I8. Actually I don't know why I'm monitoring this TA as numbers are definitely your thing and not mine -- I am a self confessed Numerophobe :->
0
Commented:
You can of course make use of bitwise operators in any of the standard algorithms for finding primes (like the sieve of Eratosthenes), but that's a bit pointless.

I know of no algorithm that is based on bitwise operators to calculate primes. For the simple reason that bitwise operators are tied to powers of 2. And that doesn't offer an advantage to finding primes, as a prime can't be divisible by any value (other than 1 and itself), not just powers of 2.
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
You might use bit operators in a Feedback Shift Register pseudo-random number generator to select the random prime once it has been generated.
0
Commented:
you might use a binary GCD algorithm for trial divisions.
You might shift by the word size to get a bit mask and an array index for doing a sieve that uses more bits than your word size.
Or maybe you want to find primes in GF(2)
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.