#include <stdio.h>
#include <stdlib.h>
#include <math.h>

static double float_rand()
{
    double p,m;
    m=10.0 * sin(0.001 * (rand() % 1000));
    p=rand() % 20 - 10;
    return pow(m,p);
}

void make_csv(int rows,int cols)
{
	int i,j,p,cp;
	FILE *out;
	out=fopen("db.csv","wt");
    if(!out)
    	return;
    for(i=p=0;i<rows;i++)
    {
    	for(j=0;j<cols-1;j++)
	    	fprintf(out,"\t %g ; ",float_rand());
	    fprintf(out,"\t %g \n\n",float_rand());
	    cp = i * 100 / rows;
        if(cp!=p)
        {
        	printf("Done: %d%% ...\n",cp);
            p=cp;
		}
	}
	fclose(out);
}

int main(int argc,char *argv[])
{
	int rows,cols;
	if(argc!=3)
    {
    	printf("Usage: %s <rows> <cols>\n",argv[0]);
        return -1;
	}
    rows=atoi(argv[1]);
    cols=atoi(argv[2]);
    if(cols<=0 || rows<=0)
    {
    	puts("Incorrect parameters");
        return -1;
	}
	srand(rows * cols);
    make_csv(rows,cols);
    return 0;
}
