#include <time.h>
// double RAND_MAX = 4294967296.0; //2147483647; //
void aleatorio();
void warmup_random(double);
void advance_random();
int flip(double);
double randomperc();
double aleatorios_0_1();
long rnd(long, long);
double Rseed; /* Random numbers seed */
double oldrand[55]; /* Array of 55 random numbers */
int jrand; /* current random number */
/* Initialize random numbers batch */
void aleatorio()
{
int j1;
time_t t;
/*srand(time(0));*/
Rseed = ((double) rand());
/*printf( "\n \n %f ", Rseed);*/
Rseed /= RAND_MAX;
for(j1=0; j1<=54; j1++)
oldrand[j1] = 0.0;
jrand=0;
warmup_random(Rseed);
}
/* Get random off and running */
void warmup_random(double random_seed)
{
int j1, ii;
double new_random, prev_random;
oldrand[54] = random_seed;
new_random = 0.000000001;
prev_random = random_seed;
for(j1 = 1 ; j1 <= 54; j1++){
ii = (21*j1)%54;
oldrand[ii] = new_random;
new_random = prev_random-new_random;
if(new_random<0.0) new_random = new_random + 1.0;
prev_random = oldrand[ii];
}
advance_random();
advance_random();
advance_random();
jrand = 0;
}
/* Create next batch of 55 random numbers */
void advance_random()
{
int j1;
double new_random;
for(j1 = 0; j1 < 24; j1++){
new_random = oldrand[j1] - oldrand[j1+31];
if(new_random < 0.0) new_random = new_random + 1.0;
oldrand[j1] = new_random;
}
for(j1 = 24; j1 < 55; j1++){
new_random = oldrand [j1] - oldrand [j1-24];
if(new_random < 0.0) new_random = new_random + 1.0;
oldrand[j1] = new_random;
}
}
/* Flip a biased coin - true if heads */
int flip(double prob){
double randomperc();
if(randomperc() <= prob)
return(1);
else
return(0);
}
/* Fetch a single random number between 0.0 and 1.0 - Subtractive Method */
/* See Knuth, D. (1969), v. 2 for details */
/* name changed from random() to avoid library conflicts on some machines*/
double randomperc()
{
jrand++;
if(jrand >= 55){
jrand = 1;
advance_random();
}
return((double) oldrand[jrand]);
}
double aleatorios_0_1(){
int i;
double x;
/* inicializacion de la semilla de aleatorios */
srand(time(0));
/* aleatorios % 0 y 1 */
for(i=0; i<10; i++){
x =(double) (((rand()%32000) / 32000.0)-1);
/* printf(" %f ", x);*/
}
return x;
}
/* Pick a random integer between low and high */
long rnd(long low, long high){
long i;
double randomperc();
if(low >= high)
i = low;
else {
i = (randomperc() * (high - low + 1)) + low;
if(i > high) i = high;
}
return(i);
}
c:\users\jana\documents\visual studio 2008\projects\misa\aleatori.c(22) : warning C4013: 'rand' undefined; assuming extern returning int
c:\users\jana\documents\visual studio 2008\projects\misa\aleatori.c(24) : error C2065: 'RAND_MAX' : undeclared identifier
c:\users\jana\documents\visual studio 2008\projects\misa\aleatori.c(99) : warning C4013: 'srand' undefined; assuming extern returning int
c:\users\jana\documents\visual studio 2008\projects\misa\aleatori.c(116) : warning C4244: '=' : conversion from 'double' to 'long', possible loss of data
Build log was saved at "file://c:\Users\jana\Documents\Visual Studio 2008\Projects\misa\misa\Debug\BuildLog.htm"
misa - 1 error(s), 3 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
adel_elrefaey
0
Newbie Poster
Recommended Answers
Jump to PostJust by looking at your errors :
You forgot to include proper library. Fastest way is to
#include<iostream> using namespace std; Although its not good
practice.
Jump to PostUse code tags - code is unreadable without code tags and formatting/indentation.
Jump to Post> #include<iostream> using namespace std; Although its not good
Except it appears to be a C program from the logs.But then again, who knows, the whole mess was posted without code tags to begin with. Don't people READ intro threads? Of course not, that would get in the …
Jump to PostThe number of errors you have in code doesn't dictate how close you are to finishing. It can go from 1 error -> 12 errors -> working.
Jump to PostOK, well the error messages say it all...
For starters you need to uncomment the definition of RAND_MAX which is the cause of your error.Secondly, as Salem has pointed out, you need to include stdlib.h, which will get rid of the warnings about rand and srand.
Finally …
All 22 Replies
adel_elrefaey
0
Newbie Poster
mrnutty
761
Senior Poster
adel_elrefaey
0
Newbie Poster
VernonDozier
2,218
Posting Expert
Featured Poster
Salem
5,138
Posting Sage
DaBunBun
18
Light Poster
JasonHippy
739
Practically a Master Poster
adel_elrefaey
0
Newbie Poster
adel_elrefaey
0
Newbie Poster
Salem
5,138
Posting Sage
adel_elrefaey
0
Newbie Poster
Salem
5,138
Posting Sage
adel_elrefaey
0
Newbie Poster
mrnutty
761
Senior Poster
adel_elrefaey
0
Newbie Poster
adel_elrefaey
0
Newbie Poster
adel_elrefaey
0
Newbie Poster
adel_elrefaey
0
Newbie Poster
Salem
5,138
Posting Sage
adel_elrefaey
0
Newbie Poster
Tom Gunn
1,164
Practically a Master Poster
adel_elrefaey
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.