Random Numbers Generator Remake

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <conio.h>
#include <string>
#include <Windows.h>
#include <ctime>

using namespace std;

int main() 
{		
		
	string Agin = "yes";
		int Key[10] = {792,12,387,1032,749,56,472,825,952,395};
		do{

			int long unsigned x = rand(), Number = rand(), Max = 0;
			cout << "What is you Maximum Number?" << endl;
			cin >> Max;

			for(int loop=0;loop<x;loop++)
			{
				int y = rand()%10;
				int z = rand()%4+1;
			
				switch(z)
				{
					case 1:
						Number+Key[y];
						break;
					case 2:
						Number-Key[y];
						break;
					case 3:
						Number/Key[y];
						break;
					case 4:
						Number*Key[y];
						break;
				}
			}

			cout << Max << "  -  " << Number%Max+1 << endl;; 
			cout << "Would you like to go agin type yes or no" << endl;
			cin >> Agin;
			cout << endl << endl;
		}while(Agin == "yes");
}


I dont really have a question im just looking for some input i created this console aplication because in the near future im going to create a bot for a game that i belive detects bots through analizeing there clicks. This means that they could even possibly check where the clicks go based on rand() so i made this short program just to randomize the numbers more...
i gues what im looking for is do you guys think its fool proof or do you see some flaws

Edit: BTW if you couldn't tell from the code it revolves around a aray called key input by a human which is what i based the randomeness around :)
You haven't seeded the prng.
srand (time (0) ); // missing from your program
Last edited on
kk ill add srand when i get home from work.... and kbw what is prng i googled but couldnt really find much on it...
what is prng


an abbreviation for Pseudo Random Number Generator

So basically what Phil123 said
Last edited on
Well i added Prng and turned it into a fuction but now it returns the same number every time can someon show me why???

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <conio.h>
#include <string>
#include <Windows.h>
#include <ctime>

using namespace std;


int main()
{
	int Prng(int Max);
	cout << Prng(1000);

	_getch();
}

int Prng(int Max) 
{
	int Key[5][10] = 
{{792,12,387,1032,749,472,825,952,395,21}, 
{21,383,492,341,764,519,364,8964,998,554}, 
{8564,865,345,1,83,232,72,978,132,419}, 
{529,21,893,529,893,69,4972,8590,750,553}, 
{3458,7,83,9134,8235,6835,936,5613,759,3453}};

	int long unsigned Times=rand(), Number=rand();
        srand((unsigned)time(0)); 

	for(int Loop=0;Loop<Times;Loop++)
	{
		int Slot1=rand()%5, Slot2=rand()%10, Equation=rand()%4+1;
		switch(Equation)
		{
			case 1:
				Number=Number+Key[Slot1][Slot2];
				break;
			case 2:
				Number=Number-Key[Slot1][Slot2];
				break;
			case 3:
				Number=Number/Key[Slot1][Slot2];
				break;
			case 4:
				Number=Number*Key[Slot1][Slot2];
				break;
		}
	}
	return Number%Max+1;
}
Last edited on
That switch doesn't do anything.
ummm how do i fix it iv been messing around with it for the last hour with no luck :(
You need to seed the generator before you call rand. What are you expecting the switch to do?
sorry switch was supose to have a difrent sighn each time... i fixed it and it still dosnt solve the problem.... and i have seeded rand line 29
srand((unsigned)time(0));
int Slot1 = rand()%5, Slot2 = rand()%10

As 5 is a factor of 10, there are only a fixed number of possibilities. LCM of them is 10

So if Slot 1 = 1, then Slot 2 = 1 or 6.
Therefore That means in every row, there are 8 elements which will never be chosen. So over all rows there are 40 elements which cannot be chosen. So Key is an effective array of 10.

A same case can be made for slot 2 and z, LCM of them is 20.

Choose numbers like 5, 6, 7. In this case any two numbers lowest common multiple is the maximum it can be. i.e LCM of 5 and 6 is 30 = 6 * 5
so how do i fix it??
Sorry, only read your original post first.

You keep getting the same numbers is the problem? I ran your code and got different numbers every time.

Sometimes when you run the code multiple times in a short space of time. The rand function gives the same result when using srand(time(NULL))

This is the only way I know how to generate random numbers. If you want to find a more advanced generator, maybe try google.
thanks for help works now... ur prob right about same numbers in short area of time bc i didnt change anything... thanks agin :)
This is the only way I know how to generate random numbers.


With C++ 11: #include <random> . You can find details on it on this site.
Might have to look into that, I am working with a RNG at the moment. Thanks
random numbers are imposible.... period a computer is not random you can only make it hard to find the pattern
Doing anything exactly is impossible.

But, you could use all sorts of mechanical imperfections in your computer (the current speed of the CPU fan, HD) to figure out something random. The lowest bit in an un-claimed Word is generally random.

Or are you saying that the universe is not random? :)


Last edited on
to shay :)
to shay :)

Touché =P
Topic archived. No new replies allowed.