[ create a new paste ] login | about

Link: http://codepad.org/d96GzyBV    [ raw code | output | fork ]

C, pasted on Nov 13:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>

static unsigned int mirand = 1;

float sfrand( void )
{
    unsigned int a;
    mirand *= 16807;
    a = (mirand&0x007fffff) | 0x40000000;
    return( *((float*)&a) - 3.0f );
}

int main ( void )
{
    int i;
    for (i = 0; i < 100; i++)
        printf("%g\n", sfrand());
    return 0;
}


Output:
-0.995993
0.347347
-0.130602
0.970146
-0.749159
0.883045
-0.655375
-0.883682
-0.0435851
-0.534137
0.751249
0.243202
-0.496458
0.0254862
0.347082
-0.594513
0.0250337
0.741604
0.139936
-0.09214
-0.596297
0.0439036
-0.112375
-0.694992
-0.727637
0.612072
-0.902041
-0.598381
-0.986174
-0.624202
-0.971247
0.252381
-0.239096
-0.485233
0.687818
0.16198
0.39641
0.458668
0.832968
-0.314895
-0.446844
-0.112812
-0.0279868
-0.373558
-0.386046
-0.269985
0.362768
-0.95932
0.711618
0.166836
0.0130441
-0.767494
0.72896
-0.372661
0.680654
-0.243393
-0.701208
0.79121
-0.126589
0.417671
-0.196074
0.588139
0.849127
-0.729614
-0.622824
0.197811
0.615614
0.619438
0.901354
-0.950084
-0.0693152
-0.980484
-0.990729
0.824139
-0.697848
-0.724693
0.0837419
-0.549831
0.987829
0.441498
0.257578
-0.892307
0.995527
-0.177223
-0.586409
0.226399
-0.916941
0.973831
-0.815405
-0.514026
0.758238
-0.300651
0.953401
-0.183895
-0.721125
0.0540164
-0.147177
0.396481
-0.347216
0.342522


Create a new paste based on this one


Comments: