mardi 28 juin 2016

rand() making same number even with srand in main function with 1 second delays

Test file: Number generated is always 30, I had it working yesterday but I dont remember what I changed that made it stop again... Checked other threads but didn't really see a solution...

    #include "stdafx.h"
    #include <iostream>
    #include <stdio.h>
    #include <Windows.h>
    #include <ctime>


    int main()
    {
        srand((unsigned int)time(NULL));

        int randomnumber = 0;

        while (true) {

            randomnumber = rand() % 1 + 30;
            std::cout << "Rand number: " << randomnumber << std::endl;
            Sleep(2000);
        }

        return 0;
    }




Aucun commentaire:

Enregistrer un commentaire