aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/embryo/src/lib/embryo_rand.c
blob: 627f7ed35c4009bebc12e1bc98ab63247665b44b (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
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdlib.h>

#include "Embryo.h"
#include "embryo_private.h"

/* exported random number api */

static Embryo_Cell
_embryo_rand_rand(Embryo_Program *ep __UNUSED__, Embryo_Cell *params __UNUSED__)
{
   return (Embryo_Cell)(rand() & 0xffff);
}

static Embryo_Cell
_embryo_rand_randf(Embryo_Program *ep __UNUSED__, Embryo_Cell *params __UNUSED__)
{
   double r;
   float f;

   r = (double)(rand() & 0xffff) / 65535.0;
   f = (float)r;
   return EMBRYO_FLOAT_TO_CELL(f);
}

/* functions used by the rest of embryo */

void
_embryo_rand_init(Embryo_Program *ep)
{
   embryo_program_native_call_add(ep, "rand",  _embryo_rand_rand);
   embryo_program_native_call_add(ep, "randf", _embryo_rand_randf);
}