Thread: Help! Getting identical random numbers?

  1. #1

    Help! Getting identical random numbers?

    In my program I'm getting the same random numbers. I've set the seed with the system time. I can't figure out the problem. Somebody help?


    #include <iostream.h>
    #include <stdlib.h>
    #include <time.h>
    #include <iomanip.h>

    void main ()
    int how_many, max, array[40000], count=0, count2, row;

    // Opening Statements

    cout<<"How many numbers? ";
    while (how_many>40000 || how_many<1)
    cout<<"Please enter a number between 1 and 40000: ";

    cout<<"How big are the numbers? ";

    //Generate random numbers

    for (count=0; count<how_many; count++)
    { srand(time(NULL));
    array[count]=rand() % max + 1;


    for (count=0; count<how_many; count++)
    { cout<<array[count]<<setw(7);



  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Well srand should only be called once, so put it before your loop.
    and it should be int main not void main

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. Doubts regarding random numbers generation
    By girish1026 in forum C Programming
    Replies: 9
    Last Post: 12-31-2008, 10:47 PM
  3. random numbers
    By mesmer in forum C Programming
    Replies: 4
    Last Post: 10-24-2008, 01:22 PM
  4. Generating 100k to 1 million unique random numbers
    By Ariod in forum C Programming
    Replies: 4
    Last Post: 08-26-2005, 12:59 PM
  5. Generate random numbers in Lucky7 project using C#
    By Grayson_Peddie in forum C# Programming
    Replies: 1
    Last Post: 04-11-2003, 11:03 PM