How?

This is a discussion on How? within the Game Programming forums, part of the General Programming Boards category; how would u get different numbers in the 2 loops? code: #include <stdlib.h> #include <time.h> #include <iostream.h> int funk1() { ...

  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

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