0
Fonction rand()
Ever time I excused program is give me same number why? It's give me like this : le point is (34.56 , 34.56 ) #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> double reel(){ srand(time(NULL)); double s=rand()%2==0?-1:1; return s*sqrt(rand()%1001); } typedef struct { double abs; double ord; } point ; point RandomPoint(){ point p; p.abs=reel(); p.ord=reel(); return p; } int main(){ point p=RandomPoint(); printf(" le point is (%.2lf , %.2lf )",p.abs,p.ord); return 0; }
6 Answers
+ 2
I made some changes from your code
https://code.sololearn.com/cjQfVPIl8heS/?ref=app
+ 1
Put this as first line in main() before call to RandomPoint()
srand( time( NULL ));
+ 1
Thank you I understand
0
Typos:
#include <stdio.h> // <studio.h>
double reel() // Double
(Edit)
OP corrected the typos in thread's Description
Seed the RNG in the main() function, not in reel() function.
srand( time( NULL ) ); // put this in main() function.
0
Do i have put RNG in the main but fonction RandomPoint () is defined with fonction real()
i did put srand(time(NULL)); but it's give me same number like le point is (-28.72 , -28.72)
0
I did it, i put srand (time(NULL)); in first line in main() but same problem same number.