I am trying to wirte a program that enciphers and deciphers files of any type.
the first thing i wanted to do was create a linear congruential generator.
Code:
unsigned random(){
int a=214013,c=2531011,m=4294967296;
x=(a*x+c)%m;
return x;
}
then i want to Use a global static variable to keep the previous X. Also, write a function to initialize the seed (which is the first X)
Code:
void startRandom(int seed)
{
x = seed;
}
then i wanted to print to see if it works
Here is my full code
Code:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
static int x;
unsigned random()
{
int a=214013,c=2531011,m=4294967296;
x=(a*x+c)%m;
return x;
}
void startRandom(int seed)
{
x = seed;
}
int main(int argc,char*argv[])
{
int seed = 5;
for(int i = 0; i<5;i++)
{
startRandom(seed);
printf((const char*)random());
}
system("pause");
return 0;
}
i am constantly getting "Unhandled exception at 0x00193D11 in Project8.exe: 0xC0000094: Integer division by zero." I am not able to continue with my program because of it. i could really use some help. I am not really good with code so maybe there is something simple that i am doing wrong that why i keep getting this error?