summaryrefslogtreecommitdiff
path: root/include/al/random.h
blob: 31da3f388b128f12852526cac22b34bbd1d0832b (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
#ifndef _AL_RANDOM_H
#define _AL_RANDOM_H

#include "lib.h"
#include "atomic.h"

#define AL_RAND_MAX RAND_MAX

AL_UNUSED_FUNCTION_PUSH

static void al_rand_init(void)
{
    srand((u32)time(NULL));
}

static s32 al_rand(void)
{
    return rand();
}

// Each file that includes this header will have a separate counter.
static atomic(u16) _al_inc_value = 0;

// This is apart of random because currently al_inc_u16() is used as a substitute
// for proper random id generation.
static u16 al_inc_u16(void)
{
    return al_atomic_add(u16)(&_al_inc_value, 1, AL_ATOMIC_RELEASE);
}

AL_UNUSED_FUNCTION_POP

#endif // _AL_RANDOM_H