Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <time.h>
- FILE *fp;
- FILE *csv;
- int generujNahodneCislo() {
- int byte_count = sizeof(int);
- int random[1];
- fread(&random, 1, byte_count, fp);
- //printf("%d\n", random[0]);
- //printf("%.10f\n", (double) random[0] / 10000000000);
- return random[0];
- }
- int main(int argc, char *argv[]) {
- fp = fopen("/dev/urandom", "r");
- csv = fopen("dev_urandom.csv", "w+");
- time_t start, stop;
- int kolik = 1;
- if (argc > 1) {
- kolik = atol(argv[1]);
- }
- printf("Kolik: %d\n", kolik);
- int cisla[kolik];
- time(&start);
- for (int i=0; i< kolik; i++) {
- cisla[i] = generujNahodneCislo();
- }
- time(&stop);
- for (int i=0; i< kolik; i++) {
- //fprintf(csv, "%d,%d\n", i, cisla[i]);
- double abc = (double) cisla[i] / 10000000000;
- fprintf(csv, "%.10f\n", abc);
- printf("Nahodne cislo c. %d = %.10f\n", i, abc);
- }
- printf("Vygenerovano: %d cisel\n", kolik);
- printf("Generovani trvalo %.000fs\n", difftime(stop, start));
- fclose(fp);
- fclose(csv);
- return 0;
- }
- // gcc -o dev_urandom dev_urandom.c -std=c99
- /* VYSTUP:
- Kolik: 10
- Nahodne cislo c. 0 = 0.1952607124
- Nahodne cislo c. 1 = 0.1485520581
- Nahodne cislo c. 2 = 0.1176588805
- Nahodne cislo c. 3 = 0.0430723194
- Nahodne cislo c. 4 = 0.1302624476
- Nahodne cislo c. 5 = -0.1477905392
- Nahodne cislo c. 6 = -0.2100886278
- Nahodne cislo c. 7 = -0.1149736942
- Nahodne cislo c. 8 = -0.0067722964
- Nahodne cislo c. 9 = 0.1352800048
- Vygenerovano: 10 cisel
- Generovani trvalo 0s
- */
Advertisement
Add Comment
Please, Sign In to add comment