random result

how come without using rand(). My program still generate random result.
I was trying to make a matrix grahic, instead my programs goes wild...
I am very curious how a solid program can generate random result

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
51
#include <iostream>
using namespace std;

int selfMadeModulus(int x, int y)
{
	return x-((x/y)*y);
}

char randomCharacter(int generator, char character, int range)
{
	return character+selfMadeModulus(generator, range);
}

int main()
{
	int a=5;
	int b=20;
	int c=4;
	int d=9;
	int e=10;
	char hold[80];
	int check=0;
	int seed=9;
	while(true)
	{
		int i=1;
		if(hold[i]!=' ')
			hold[i]=randomCharacter(seed*i*i, 'a', 30);
		++i;
		
		cout << hold[i];
		check*=seed%100;
		seed+=2+check;
		hold[selfMadeModulus(a, 80)]=' ';
		hold[selfMadeModulus(b, 80)]=' ';
		hold[selfMadeModulus(c, 80)]=' ';
		hold[selfMadeModulus(d, 80)]=' ';
		hold[selfMadeModulus(e, 80)]=' ';
		
		if(i==80)
		{
			a+=13;
			b+=44;
			c+=33;
			d+=45;
			e+=49;
			i=0;
		}
	}
}
You never initialize any data in hold so it takes on whatever memory is left over from whatever used to be there.
You're outputting characters from hold[] that aren't initialised; if you don't initialise variables, they can hold any random data going.

Jim
Thanks a lot!
Always got answers so quick here!
Topic archived. No new replies allowed.