I need to call that function alot, because I need to generate alot of random numbers and I understand it wont be anymore random thats obvious..
see the code
Code:
#include "console.h"
#include <iostream>
#include <stdlib.h>
#include "lib.h"
#include <time.h>
#include <windows.h>
#define MAX_WALK 25
using namespace std;
int StartX = RandX();
int StartY = RandY();
int Direc;
int MyEndKey;
int RandDir()
{
Sleep(1000);
srand(time(NULL));
Direc = rand()%4;
if (Direc == 0)
{
MoveCursor(StartX, StartY);
cout << " ";
StartY--;
MoveCursor(StartX, StartY);
cout << "*";
}
if (Direc == 1)
{
MoveCursor(StartX, StartY);
cout << " ";
StartY++;
MoveCursor(StartX, StartY);
cout << "*";
}
if (Direc == 2)
{
MoveCursor(StartX, StartY);
cout << " ";
StartX--;
MoveCursor(StartX, StartY);
cout << "*";
}
if (Direc == 3)
{
MoveCursor(StartX, StartY);
cout << " ";
StartX++;
MoveCursor(StartX, StartY);
cout << "*";
}
return Direc;
}
int main()
{
MoveCursor(StartX, StartY);
cout << "*";
do
{
int MyEndKey;
MyEndKey = PeekVirtualKey();
RandDir();
} while (MyEndKey != VK_ESCAPE);
return 0;
}
i just wanted to test it, thats why I did what I did, and i got te same values if i repeated RandDir really fast, I needed to know why thats all. I got the same value over and over and all I needed to know was how to change that, i know now, thanx for that..