View | Details | Raw Unified | Return to bug 193147 | Differences between
and this patch

Collapse All | Expand All

(-)awk.1 (working copy) (-1 / +1 lines)
Lines 208-214 Link Here
208
if no argument.
208
if no argument.
209
.TP
209
.TP
210
.B rand
210
.B rand
211
random number on (0,1)
211
random number on [0,1)
212
.TP
212
.TP
213
.B srand
213
.B srand
214
sets seed for
214
sets seed for
(-)main.c (working copy) (-1 / +1 lines)
Lines 74-80 Link Here
74
       signal(SIGFPE, fpecatch);
74
       signal(SIGFPE, fpecatch);
75
       srand_seed = 1;
75
       srand_seed = 1;
76
       srand(srand_seed);
76
       srandom((unsigned long) srand_seed);
77
       yyin = NULL;
77
       yyin = NULL;
78
       symtab = makesymtab(NSYMTAB/NSYMTAB);
78
       symtab = makesymtab(NSYMTAB/NSYMTAB);
(-)run.c (working copy) (-3 / +5 lines)
Lines 1521-1528 Link Here
1521
               u = (Awkfloat) system(getsval(x)) / 256;   /* 256 is unix-dep */
1521
               u = (Awkfloat) system(getsval(x)) / 256;   /* 256 is unix-dep */
1522
               break;
1522
               break;
1523
       case FRAND:
1523
       case FRAND:
1524
               /* in principle, rand() returns something in 0..RAND_MAX */
1524
               /* random() returns numbers in [0..2^31-1]
1525
               u = (Awkfloat) (rand() % RAND_MAX) / RAND_MAX;
1525
                * in order to get a number in [0, 1), divide it by 2^31
1526
                */
1527
               u = (Awkfloat) random() / (0x7fffffffL + 0x1UL);
1526
               break;
1528
               break;
1527
       case FSRAND:
1529
       case FSRAND:
1528
               if (isrec(x))   /* no argument provided */
1530
               if (isrec(x))   /* no argument provided */
Lines 1530-1536 Link Here
1530
               else
1532
               else
1531
                       u = getfval(x);
1533
                       u = getfval(x);
1532
               tmp = u;
1534
               tmp = u;
1533
               srand((unsigned int) u);
1535
               srandom((unsigned long) u);
1534
               u = srand_seed;
1536
               u = srand_seed;
1535
               srand_seed = tmp;
1537
               srand_seed = tmp;
1536
               break;
1538
               break;

Return to bug 193147