/*
Copyright (C) 2001-2007, The Perl Foundation.
$Id: /mirror/trunk/src/pmc/random.pmc 26316 2008-03-11T09:50:21.102015Z allison  $

=head1 NAME

src/pmc/random.pmc - Random Numbers

=head1 DESCRIPTION

These are the vtable functions for the Random base class.

This is a singleton (monadic) class - only one instance exists.

=head2 Methods

=over 4

=cut

*/

#include "parrot/parrot.h"

static PMC *Rand_PMC;

pmclass Random singleton {

/*

=item C<void class_init()>

Class initialization.  Clears the singleton PMC.

=cut

*/

    void class_init() {
        Rand_PMC = NULL;
    }

/*

=item C<void *get_pointer()>

=cut

*/

    VTABLE void *get_pointer() {
        return Rand_PMC;
    }

/*

=item C<void set_pointer(void *ptr)>

These two functions are part of the singleton creation interface. For more
information see F<src/pmc.c>.

=cut

*/

    VTABLE void set_pointer(void *ptr) {
        PARROT_ASSERT(!Rand_PMC);
        Rand_PMC = (PMC *)ptr;
    }

/*

=item C<void set_integer_native(INTVAL seed)>

Sets the random number seed to C<seed>.

=cut

*/

    VTABLE void set_integer_native(INTVAL seed) {
        Parrot_srand(seed);
    }

/*

=item C<INTVAL get_integer()>

Returns a random integer in the range C<-2^31..2^31>.

=cut

*/

    VTABLE INTVAL get_integer() {
        return Parrot_int_rand(0);
    }

/*

=item C<INTVAL get_integer_keyed_int(INTVAL max)>

Returns a random integer in the range C<0..max>.

=cut

*/

    VTABLE INTVAL get_integer_keyed_int(INTVAL max) {
        return Parrot_range_rand(0, max, 0);
    }

/*

=item C<FLOATVAL get_number()>

Returns a random floating-point number in the range C<0.0..1.0>.

=cut

*/

    VTABLE FLOATVAL get_number() {
        return Parrot_float_rand(0);
    }

}

/*

=back

=head1 HISTORY

2003.12.10  first rev by leo.

=cut

*/


/*
 * Local variables:
 *   c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4:
 */
