iPXE
Functions | Variables
random.c File Reference

Random number generation. More...

#include <stdlib.h>
#include <ipxe/timer.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
void srandom (unsigned int seed)
 Seed the pseudo-random number generator.
long int random (void)
 Generate a pseudo-random number between 0 and 2147483647L or 2147483562?

Variables

static int32_t rnd_seed = 0

Detailed Description

Random number generation.

Definition in file random.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
void srandom ( unsigned int  seed)

Seed the pseudo-random number generator.

Parameters:
seedSeed value

Definition at line 19 of file random.c.

References rnd_seed.

Referenced by random(), srand(), and tcpip_random_okx().

                                   {
        rnd_seed = seed;
        if ( ! rnd_seed )
                rnd_seed = 4; /* Chosen by fair dice roll */
}
long int random ( void  )

Generate a pseudo-random number between 0 and 2147483647L or 2147483562?

Return values:
randPseudo-random number

Definition at line 30 of file random.c.

References currticks(), rnd_seed, and srandom().

Referenced by arbel_alloc_qpn(), cipher_cost(), digest_cost(), dns_send_packet(), efi_pxe_udp_write(), efi_snp_hii_random_guid(), eth_random_addr(), forcedeth_open(), hermon_alloc_qpn(), http_digest_authenticate(), ib_create_conn(), ib_create_qp(), inject_corruption_nonzero(), inject_fault_nonzero(), iscsi_handle_chap_c_value(), iscsi_open_connection(), loopback_test(), memcpy_test_speed(), ntlm_response(), peerdisc_create(), profile_test_exec(), rand(), start_dhcp(), start_dhcpv6(), tcp_open(), tcpip_bind(), tcpip_random_okx(), tls_new_server_hello(), tls_send_client_hello(), vmbus_open(), and wep_encrypt().

                         {
        int32_t q;

        if ( ! rnd_seed ) /* Initialize linear congruential generator */
                srandom ( currticks() );

        /* simplified version of the LCG given in Bruce Schneier's
           "Applied Cryptography" */
        q = ( rnd_seed / 53668 );
        rnd_seed = ( 40014 * ( rnd_seed - 53668 * q ) - 12211 * q );
        if ( rnd_seed < 0 )
                rnd_seed += 2147483563L;
        return rnd_seed;
}

Variable Documentation

int32_t rnd_seed = 0 [static]

Definition at line 12 of file random.c.

Referenced by random(), and srandom().