Thread: How?

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    479

    How?

    how would u get different numbers in the 2 loops?
    code:
    #include <stdlib.h>
    #include <time.h>
    #include <iostream.h>

    int funk1()
    {

    srand((unsigned)time(NULL));

    int d=rand()%7;
    cout<<d<<flush;
    return 0;

    }
    int funk2()
    {

    srand((unsigned)time(NULL));

    int d=rand()%7;

    cout<<d<<flush;
    return 0;
    }
    main()
    {
    funk1();
    cout<<"--";
    funk2();
    return 0;
    }

  2. #2
    Barjor
    Guest
    Loops? If you are talking about functions....you should only seed rand once.
    ~Barjor

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    411
    yes only make one call to srand in the whole entire complete program.

Popular pages Recent additions subscribe to a feed