iPXE
Functions | Variables
random.c File Reference

Random number generation. More...

#include <stddef.h>
#include <stdlib.h>
#include <time.h>

Go to the source code of this file.

Functions

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

Variables

static int32_t rnd_seed = 0
 

Detailed Description

Random number generation.

Definition in file random.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ srandom()

void srandom ( unsigned int  seed)

Seed the pseudo-random number generator.

Parameters
seedSeed value

Definition at line 21 of file random.c.

21  {
22  rnd_seed = seed;
23  if ( ! rnd_seed )
24  rnd_seed = 4; /* Chosen by fair dice roll */
25 }
static int32_t rnd_seed
Definition: random.c:14

References rnd_seed.

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

◆ random()

long int random ( void  )

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

Return values
randPseudo-random number

Definition at line 32 of file random.c.

32  {
33  int32_t q;
34 
35  /* Initialize linear congruential generator */
36  if ( ! rnd_seed )
37  srandom ( time ( NULL ) );
38 
39  /* simplified version of the LCG given in Bruce Schneier's
40  "Applied Cryptography" */
41  q = ( rnd_seed / 53668 );
42  rnd_seed = ( 40014 * ( rnd_seed - 53668 * q ) - 12211 * q );
43  if ( rnd_seed < 0 )
44  rnd_seed += 2147483563L;
45  return rnd_seed;
46 }
static int32_t rnd_seed
Definition: random.c:14
void srandom(unsigned int seed)
Seed the pseudo-random number generator.
Definition: random.c:21
signed int int32_t
Definition: stdint.h:17
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References NULL, rnd_seed, and srandom().

Referenced by arbel_alloc_qpn(), cipher_cost(), digest_cost(), dns_send_packet(), eap_rx_mschapv2_request(), 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_client_hello(), tls_new_server_hello(), tls_send_client_key_exchange_pubkey(), vmbus_open(), and wep_encrypt().

Variable Documentation

◆ rnd_seed

int32_t rnd_seed = 0
static

Definition at line 14 of file random.c.

Referenced by random(), and srandom().