Re: Extremely poor performance crunching random numbers under PIV-FC5

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Filling szBufferState with random data is completely unnecessary,
initstate_r overwrites it anyway.
If you want to initialize randomdataState the same way srandom(seconds);
does, don't open /dev/urandom at all and just do:
static int buf[32];
memset (randomdataState, 0, sizeof (*randomdataState));
initstate_r (seconds, (char *) buf, 128, &randomdataState);

Jakub, I have tried to do what you propose but the following code is
throwing an error in execution time:

### prueba-3.c ##################################################
	#include <stdio.h>
	#include <stdlib.h>
	#include <fcntl.h>

	int bucle_random_r() {
		int nRandom;
		struct random_data *randomdataState;
		static int buf[32];
		time_t seconds;
		extern void *memset (void *__s, int __c, size_t __n) __THROW;

		memset(randomdataState, 0, sizeof(*randomdataState));
		initstate_r(seconds, (char *) buf, 128, randomdataState);

		random_r(randomdataState, &nRandom);
		printf("%d\n", nRandom);

		return 1;
	}


	int main(int argc, char ** argv) {
		bucle_random_r();
		return (0);
	}
#################################################################

This is the result:
	# gcc prueba-3.c -o 3prueba -Wall -pedantic -O0

	#./3prueba
	Segmentation fault

The "Segmentation fault" occurs when executing memset instruction. I
don't know why ...


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux