summaryrefslogtreecommitdiff
path: root/orc-test/orcrandom.c
blob: 0f53963c84fd1302e80b0d381f69b04e376078c7 (plain)
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;
}