Random Number Generator

This is a discussion on Random Number Generator within the C++ Programming forums, part of the General Programming Boards category; HI .. i was wandering if i have a program that works out if it is prime or not, how ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    19

    Random Number Generator

    HI .. i was wandering if i have a program that works out if it is prime or not, how do i generate random numbers for a prime number..

    e.g, i have entered an integer say 2, then i work out if it is prime and i call the function isprime(x) or something...but i want to generate prime numbers less than equal to 128. how do i do that..

    kind regards,
    atif

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    There is no way (not yet, at least) to generate a random prime number. What you could do is calculating all primes less than 128, store them in an array then pick a random element from that array, thus getting a random prime.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 02:31 AM
  2. Good Random Number Generator
    By MethodMan in forum C Programming
    Replies: 4
    Last Post: 11-18-2004, 06:38 AM
  3. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 03:40 PM
  4. how to link random number generator with cpu?
    By chris285 in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2003, 06:26 AM
  5. Seeding Random Number Generator
    By zdude in forum C++ Programming
    Replies: 2
    Last Post: 09-05-2002, 04:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21