File: convert.c

package info (click to toggle)
sprng 2.0a-16
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,308 kB
  • sloc: ansic: 30,353; fortran: 1,618; makefile: 575; cpp: 58; sh: 5
file content (57 lines) | stat: -rw-r--r-- 1,804 bytes parent folder | download | duplicates (9)
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
/***************************************************************************/
/*            ____Demonstrates converting code to SPRNG____                */
/* The original random number call is to 'myrandom'. We change it to call  */
/* SPRNG by defining a macro.                                 */

/* The lines between the '#ifdef CONVERT' and the '#else' are the
   newly added lines. Those lines between the '#else' and the '#endif'
   are theoriginal lines that need to be deleted.
   */
/***************************************************************************/

#include <stdio.h>
#define CONVERT        /* used to set on the macro 'myrandom --> sprng'    */ 
#ifdef CONVERT
#define SIMPLE_SPRNG		/* simple interface                        */
#include "sprng.h"              /* SPRNG header file                       */

#define myrandom sprng		/* we define this macro to make SPRNG calls*/
#endif

#define SEED 985456376

double myrandom();

main()
{
  int seed, i;
  double rn;
  int gtype;  /*---    */

#ifdef CONVERT
  /*--- 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", &gtype);

  /************************** Initialization *******************************/
  /******* We add the following optional initialization lines **************/
  init_sprng(gtype,SEED,SPRNG_DEFAULT);  /* initialize stream   */
  printf("Print information about random number stream:\n");
  print_sprng();	
#else
  /* Old initialization lines*/
#endif    
        
  /*********************** print random numbers ****************************/

  printf("Printing 3 random numbers in [0,1):\n");
  for (i=0;i<3;i++)
  {
    rn = myrandom();		/* generate double precision random number */
    printf("%f\n", rn);
  }


}