File: orcrandom.c

package info (click to toggle)
orc 1:0.4.6-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,856 kB
  • ctags: 2,889
  • sloc: ansic: 29,000; sh: 10,220; xml: 2,508; makefile: 196
file content (47 lines) | stat: -rw-r--r-- 775 bytes parent folder | download | duplicates (7)
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

#include "config.h"

#include <orc-test/orctest.h>
#include <orc-test/orcrandom.h>
#include <orc/orc.h>
#include <orc/orcdebug.h>



void
orc_random_init (OrcRandomContext *context, int seed)
{

  context->x = seed;

}



void
orc_random_bits (OrcRandomContext *context, void *data, int n_bytes)
{
  orc_uint8 *d = data;
  int i;
  for(i=0;i<n_bytes;i++){
    context->x = 1103515245*context->x + 12345;
    d[i] = context->x>>16;
  }
}

void
orc_random_floats (OrcRandomContext *context, float *data, int n)
{
  int i;
  for(i=0;i<n;i++){
    context->x = 1103515245*context->x + 12345;
    data[i] = (double)(context->x>>16) / 32768.0 - 1.0;
  }
}

unsigned int
orc_random (OrcRandomContext *context)
{
  context->x = 1103515245*context->x + 12345;
  return context->x;
}