FairRoot/PandaRoot
Classes | Macros | Functions | Variables
ranlxs.cxx File Reference
#include <limits.h>
#include <float.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

Go to the source code of this file.

Classes

struct  vec_t
 
struct  dble_vec_t
 

Macros

#define RANLXS_C
 
#define BASE   0x1000000
 
#define MASK   0xffffff
 
#define STEP(pi, pj)
 

Functions

static void error (int no)
 
static void update (void)
 
static void define_constants (void)
 
void rlxs_init (int level, int seed)
 
void ranlxs (float r[], int n)
 
int rlxs_size (void)
 
void rlxs_get (int state[])
 
void rlxs_reset (int state[])
 

Variables

static int init =0
 
static int pr
 
static int prm
 
static int ir
 
static int jr
 
static int is
 
static int is_old
 
static int next [96]
 
static float one_bit
 
static vec_t carry
 
union {
   dble_vec_t   vec [12]
 
   int   num [96]
 
x
 

Macro Definition Documentation

#define BASE   0x1000000

Definition at line 359 of file ranlxs.cxx.

#define MASK   0xffffff

Definition at line 360 of file ranlxs.cxx.

#define RANLXS_C

Definition at line 41 of file ranlxs.cxx.

#define STEP (   pi,
  pj 
)

Definition at line 382 of file ranlxs.cxx.

Referenced by update().

Function Documentation

static void define_constants ( void  )
static

Definition at line 484 of file ranlxs.cxx.

Referenced by rlxs_init(), and rlxs_reset().

485 {
486  int k;
487 
488  one_bit=(float)(ldexp(1.0,-24));
489 
490  for (k=0;k<96;k++)
491  next[k]=(k+1)%96;
492 }
static float one_bit
Definition: ranlxs.cxx:373
static int next[96]
Definition: ranlxs.cxx:372
static void error ( int  no)
static

Definition at line 417 of file ranlxs.cxx.

References exit(), and printf().

Referenced by rlxs_get(), rlxs_init(), and rlxs_reset().

418 {
419  switch(no)
420  {
421  case 0:
422  printf("Error in rlxs_init\n");
423  printf("Arithmetic on this machine is not suitable for ranlxs\n");
424  break;
425  case 1:
426  printf("Error in subroutine rlxs_init\n");
427  printf("Bad choice of luxury level (should be 0,1 or 2)\n");
428  break;
429  case 2:
430  printf("Error in subroutine rlxs_init\n");
431  printf("Bad choice of seed (should be between 1 and 2^31-1)\n");
432  break;
433  case 3:
434  printf("Error in rlxs_get\n");
435  printf("Undefined state (ranlxs is not initialized)\n");
436  break;
437  case 4:
438  printf("Error in rlxs_reset\n");
439  printf("Arithmetic on this machine is not suitable for ranlxs\n");
440  break;
441  case 5:
442  printf("Error in rlxs_reset\n");
443  printf("Unexpected input data\n");
444  break;
445  }
446  printf("Program aborted\n");
447  exit(0);
448 }
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
exit(0)
void ranlxs ( float  r[],
int  n 
)
Author
Manuel Zambrana zambr.nosp@m.ana@.nosp@m.kph.u.nosp@m.ni-m.nosp@m.ainz..nosp@m.de and Dmitry Khaneftd khane.nosp@m.ftd@.nosp@m.kph.u.nosp@m.ni-m.nosp@m.ainz..nosp@m.de

Mainz, May 2011

Definition at line 566 of file ranlxs.cxx.

References is, n, rlxs_init(), update(), and x.

567 {
568  int k;
569 
570  if (init==0)
571  rlxs_init(0,1);
572 
573  for (k=0;k<n;k++)
574  {
575  is=next[is];
576  if (is==is_old)
577  update();
578  r[k]=one_bit*(float)(x.num[is]);
579  }
580 }
double r
Definition: RiemannTest.C:14
static float one_bit
Definition: ranlxs.cxx:373
int n
static int is_old
Definition: ranlxs.cxx:372
static int init
Definition: ranlxd.cxx:374
static int is
Definition: ranlxs.cxx:372
Double_t x
static void update(void)
Definition: ranlxs.cxx:451
void rlxs_init(int level, int seed)
Definition: ranlxs.cxx:495
static int next[96]
Definition: ranlxs.cxx:372
void rlxs_get ( int  state[])

Definition at line 589 of file ranlxs.cxx.

References vec_t::c1, vec_t::c2, vec_t::c3, vec_t::c4, error(), pr, rlxs_size(), and x.

590 {
591  int k;
592 
593  if (init==0)
594  error(3);
595 
596  state[0]=rlxs_size();
597 
598  for (k=0;k<96;k++)
599  state[k+1]=x.num[k];
600 
601  state[97]=carry.c1;
602  state[98]=carry.c2;
603  state[99]=carry.c3;
604  state[100]=carry.c4;
605 
606  state[101]=pr;
607  state[102]=ir;
608  state[103]=jr;
609  state[104]=is;
610 }
static int ir
Definition: ranlxs.cxx:372
int c2
Definition: ranlxd.cxx:366
int c4
Definition: ranlxd.cxx:366
static int init
Definition: ranlxd.cxx:374
int rlxs_size(void)
Definition: ranlxs.cxx:583
static int is
Definition: ranlxs.cxx:372
int c3
Definition: ranlxd.cxx:366
static void error(int no)
Definition: ranlxs.cxx:417
static int jr
Definition: ranlxs.cxx:372
static vec_t carry
Definition: ranlxs.cxx:374
int c1
Definition: ranlxd.cxx:366
static int pr
Definition: ranlxs.cxx:372
Double_t x
void rlxs_init ( int  level,
int  seed 
)

Definition at line 495 of file ranlxs.cxx.

References vec_t::c1, vec_t::c2, vec_t::c3, vec_t::c4, define_constants(), error(), i, pr, seed, and x.

Referenced by ranlxs().

496 {
497  int i,k,l;
498  int ibit,jbit,xbit[31];
499  int ix,iy;
500 
501  if ((INT_MAX<2147483647)||(FLT_RADIX!=2)||(FLT_MANT_DIG<24))
502  error(0);
503 
505 
506  if (level==0)
507  pr=109;
508  else if (level==1)
509  pr=202;
510  else if (level==2)
511  pr=397;
512  else
513  error(1);
514 
515  i=seed;
516 
517  for (k=0;k<31;k++)
518  {
519  xbit[k]=i%2;
520  i/=2;
521  }
522 
523  if ((seed<=0)||(i!=0))
524  error(2);
525 
526  ibit=0;
527  jbit=18;
528 
529  for (i=0;i<4;i++)
530  {
531  for (k=0;k<24;k++)
532  {
533  ix=0;
534 
535  for (l=0;l<24;l++)
536  {
537  iy=xbit[ibit];
538  ix=2*ix+iy;
539 
540  xbit[ibit]=(xbit[ibit]+xbit[jbit])%2;
541  ibit=(ibit+1)%31;
542  jbit=(jbit+1)%31;
543  }
544 
545  if ((k%4)==i)
546  ix=16777215-ix;
547 
548  x.num[4*k+i]=ix;
549  }
550  }
551 
552  carry.c1=0;
553  carry.c2=0;
554  carry.c3=0;
555  carry.c4=0;
556 
557  ir=0;
558  jr=7;
559  is=95;
560  is_old=0;
561  prm=pr%12;
562  init=1;
563 }
Int_t i
Definition: run_full.C:25
static int prm
Definition: ranlxs.cxx:372
static int ir
Definition: ranlxs.cxx:372
int c2
Definition: ranlxd.cxx:366
static int is_old
Definition: ranlxs.cxx:372
int c4
Definition: ranlxd.cxx:366
static int init
Definition: ranlxd.cxx:374
static int is
Definition: ranlxs.cxx:372
static void define_constants(void)
Definition: ranlxs.cxx:484
int c3
Definition: ranlxd.cxx:366
static void error(int no)
Definition: ranlxs.cxx:417
static int jr
Definition: ranlxs.cxx:372
unsigned int seed
static vec_t carry
Definition: ranlxs.cxx:374
int c1
Definition: ranlxd.cxx:366
static int pr
Definition: ranlxs.cxx:372
Double_t x
void rlxs_reset ( int  state[])

Definition at line 613 of file ranlxs.cxx.

References vec_t::c1, vec_t::c2, vec_t::c3, vec_t::c4, define_constants(), error(), ir, pr, rlxs_size(), and x.

614 {
615  int k;
616 
617  if ((INT_MAX<2147483647)||(FLT_RADIX!=2)||(FLT_MANT_DIG<24))
618  error(4);
619 
621 
622  if (state[0]!=rlxs_size())
623  error(5);
624 
625  for (k=0;k<96;k++)
626  {
627  if ((state[k+1]<0)||(state[k+1]>=167777216))
628  error(5);
629 
630  x.num[k]=state[k+1];
631  }
632 
633  if (((state[97]!=0)&&(state[97]!=1))||
634  ((state[98]!=0)&&(state[98]!=1))||
635  ((state[99]!=0)&&(state[99]!=1))||
636  ((state[100]!=0)&&(state[100]!=1)))
637  error(5);
638 
639  carry.c1=state[97];
640  carry.c2=state[98];
641  carry.c3=state[99];
642  carry.c4=state[100];
643 
644  pr=state[101];
645  ir=state[102];
646  jr=state[103];
647  is=state[104];
648  is_old=8*ir;
649  prm=pr%12;
650  init=1;
651 
652  if (((pr!=109)&&(pr!=202)&&(pr!=397))||
653  (ir<0)||(ir>11)||(jr<0)||(jr>11)||(jr!=((ir+7)%12))||
654  (is<0)||(is>95))
655  error(5);
656 }
static int prm
Definition: ranlxs.cxx:372
static int ir
Definition: ranlxs.cxx:372
int c2
Definition: ranlxd.cxx:366
static int is_old
Definition: ranlxs.cxx:372
int c4
Definition: ranlxd.cxx:366
static int init
Definition: ranlxd.cxx:374
int rlxs_size(void)
Definition: ranlxs.cxx:583
static int is
Definition: ranlxs.cxx:372
static void define_constants(void)
Definition: ranlxs.cxx:484
int c3
Definition: ranlxd.cxx:366
static void error(int no)
Definition: ranlxs.cxx:417
static int jr
Definition: ranlxs.cxx:372
static vec_t carry
Definition: ranlxs.cxx:374
int c1
Definition: ranlxd.cxx:366
static int pr
Definition: ranlxs.cxx:372
Double_t x
int rlxs_size ( void  )

Definition at line 583 of file ranlxs.cxx.

Referenced by rlxs_get(), and rlxs_reset().

584 {
585  return(105);
586 }
static void update ( void  )
static

Definition at line 451 of file ranlxs.cxx.

References d, ir, is, jr, pi, pr, prm, STEP, and x.

Referenced by ranlxs().

452 {
453  int k,kmax,d;
454  dble_vec_t *pmin,*pmax,*pi,*pj;
455 
456  kmax=pr;
457  pmin=&x.vec[0];
458  pmax=pmin+12;
459  pi=&x.vec[ir];
460  pj=&x.vec[jr];
461 
462  for (k=0;k<kmax;k++)
463  {
464  STEP(pi,pj);
465  pi+=1;
466  pj+=1;
467  if (pi==pmax)
468  pi=pmin;
469  if (pj==pmax)
470  pj=pmin;
471  }
472 
473  ir+=prm;
474  jr+=prm;
475  if (ir>=12)
476  ir-=12;
477  if (jr>=12)
478  jr-=12;
479  is=8*ir;
480  is_old=is;
481 }
TObjArray * d
static int prm
Definition: ranlxs.cxx:372
static int ir
Definition: ranlxs.cxx:372
#define pi
Definition: createSTT.C:60
static int is_old
Definition: ranlxs.cxx:372
static int is
Definition: ranlxs.cxx:372
static int jr
Definition: ranlxs.cxx:372
static int pr
Definition: ranlxs.cxx:372
Double_t x
#define STEP(pi, pj)
Definition: ranlxs.cxx:382

Variable Documentation

vec_t carry
static

Definition at line 374 of file ranlxs.cxx.

int init =0
static

Definition at line 372 of file ranlxs.cxx.

int ir
static

Definition at line 372 of file ranlxs.cxx.

Referenced by rlxs_reset(), and update().

int is
static

Definition at line 372 of file ranlxs.cxx.

Referenced by ranlxs(), and update().

int is_old
static

Definition at line 372 of file ranlxs.cxx.

int jr
static

Definition at line 372 of file ranlxs.cxx.

Referenced by update().

int next[96]
static

Definition at line 372 of file ranlxs.cxx.

int num[96]

Definition at line 379 of file ranlxs.cxx.

float one_bit
static

Definition at line 373 of file ranlxs.cxx.

int pr
static

Definition at line 372 of file ranlxs.cxx.

Referenced by rlxs_get(), rlxs_init(), rlxs_reset(), and update().

int prm
static

Definition at line 372 of file ranlxs.cxx.

Referenced by update().

dble_vec_t vec[12]

Definition at line 378 of file ranlxs.cxx.

union { ... } x