/usr/share/doc/libsprng2-doc/EXAMPLES/spawn.c is in libsprng2-doc 2.0a-10.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | /***************************************************************************/
/* ____Demonstrates the use of spawn_sprng____ */
/* A random number stream is initialized and a few random numbers are */
/* printed. Then two streams are spawned and a few numbers from one of them*/
/* is printed. */
/***************************************************************************/
#include <stdio.h>
/* Uncomment the following line to get the interface with pointer checking */
/*#define CHECK_POINTERS */
#include "sprng.h" /* SPRNG header file */
#define SEED 985456376
main()
{
int streamnum, nstreams, *stream, **new;
double rn;
int i, irn, nspawned;
int gtype; /*--- */
/*--- reading in a generator type */
#include "gen_types_menu.h"
printf("Type in a generator type (integers: 0,1,2,3,4,5): ");
scanf("%d", >ype);
/****************** Initialization values *******************************/
streamnum = 0;
nstreams = 1;
stream = init_sprng(gtype,streamnum,nstreams,SEED,SPRNG_DEFAULT); /* initialize stream */
printf(" Print information about stream:\n");
print_sprng(stream);
/*********************** print random numbers ***************************/
printf(" Printing 2 random numbers in [0,1):\n");
for (i=0;i<2;i++)
{
rn = sprng(stream); /* generate double precision random number*/
printf("%f\n", rn);
}
/**************************** spawn streams *****************************/
printf(" Spawned two streams\n");
nspawned = 2;
nspawned = spawn_sprng(stream,2,&new); /* spawn 2 streams */
if(nspawned != 2)
{
fprintf(stderr,"Error: only %d streams spawned\n", nspawned);
exit(1);
}
printf(" Information on first spawned stream:\n");
print_sprng(new[0]);
printf(" Information on second spawned stream:\n");
print_sprng(new[1]);
printf(" Printing 2 random numbers from second spawned stream:\n");
for (i=0;i<2;i++)
{
rn = sprng(new[1]); /* generate a random number */
printf("%f\n", rn);
}
/*************************** free memory ********************************/
free_sprng(stream); /* free memory used to store stream state */
free_sprng(new[0]); /* free memory used to store stream state */
free_sprng(new[1]); /* free memory used to store stream state */
free(new);
}
|