#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
float IntervalRand(int from, int to)
{
int res;
// Obtain a random interval with rand, then linearly scale
// it to the interval [from, to]
// rand returns an integer in [0, RAND_MAX]
// to scale it to [from, to] we use the equation
// (rand - 0)/(RAND_MAX -0) * (to-from) + from
res = (((float)rand() * (to-from))/RAND_MAX)+ from;
return res;
}
main()
{
int seed, i;
float number;
char xaraktiras;
seed = time(NULL);
srand(seed);
FILE *fp;
char x[100];
int a, n, sas;
a = 101;
n = 10001;
while(n > 1000){
printf("parakalo doste ton arithmo n\n");
scanf("%d", &n);
if(n > 1000)
printf("o arithmos prepi na ine mikroteros i isos toy 1000, parakalo ksanadoste\n");
}
while( a > 100){
printf("parakalo doste to onoma toy arxeioy\n");
scanf("%s", &x);
a = strlen(x);
if(a > 100)
printf("prepi to onoma na ine mikrotero twn 100 grammatwn\n");
}
xaraktiras = 'c';
while(xaraktiras != 'b' && xaraktiras != 't'){
printf("parakalo doste t i b, t gia arxeio keimenoy kai b gia diadiko\n");
scanf("%s", &xaraktiras);
}
if(xaraktiras == 't'){
fp = fopen(x, "w");
fprintf(fp, "%d\n", n);
for(i = 0; i < n; i++)
fprintf(fp, "%.4f\n", IntervalRand(10000,0)/10000);
fclose(fp);
}
else{
fp = fopen(x, "wb");
fwrite(&n, 2 , 1, fp);
fclose(fp);
}
}