Chapter 12
Miscellaneous OSKit Interfaces

This chapter describes additional COM interfaces defined by the OSKit.

12.1 oskit_random: Interface for random number generators

The oskit_random COM interface provides a simple encapsulation for pseudo-random number generators. The interface is based on the common C library functions random and srandom. The interface inherits from oskit_iunknown and provides the following additional methods:

random:
Produce a pseudo-random number in the range 0 to 231 - 1.
srandom:
Seed the random number generator.

The oskit_random_create function can be used to create instances of the oskit_random interface.

12.1.1 create: Create a new pseudo-random number generator

SYNOPSIS

#include <oskit/com/random.h>

oskit_error_t oskit_random_create([out] oskit_random_t **out_r);

DESCRIPTION

Create a new oskit_random object in the default seed state.

PARAMETERS
out_r:
Upon success, the new oskit_random object reference is returned in *out_r.
RETURNS

Upon success, returns 0. Upon failure, the return value is set to a code indicating the reason for failure. (See <oskit/error.h>.)

12.1.2 random: Produce a pseudo-random number

SYNOPSIS

#include <oskit/com/random.h>

OSKIT_COMDECL oskit_random_random(oskit_random_t *r, [out] oskit_s32_t *out_num);

DESCRIPTION

Use r to generate a new pseudo-random number in the range 0 to 231 - 1.

PARAMETERS
r:
The random number generator object reference.
out_num:
Upon success, the newly generated number is stored in *out_num.
RETURNS

Upon success, returns 0. Upon failure, the return value is set to a code indicating the reason for failure. (See <oskit/error.h>.)

12.1.3 srandom: Seed a pseudo-random number generator

SYNOPSIS

#include <oskit/com/random.h>

OSKIT_COMDECL oskit_random_srandom(oskit_random_t *r, oskit_u32_t seed);

DESCRIPTION

Use seed to reinitialize the random number generator r.

PARAMETERS
r:
The random number generator object reference.
seed:
The seed value with which to reset the generator.
RETURNS

Upon success, returns 0. Upon failure, the return value is set to a code indicating the reason for failure. (See <oskit/error.h>.)