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)
 
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  )

◆ srandom()

void srandom ( unsigned int  seed)

Seed the pseudo-random number generator.

Parameters
seedSeed value

Definition at line 20 of file random.c.

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

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 31 of file random.c.

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

References NULL, rnd_seed, srandom(), and time.

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 13 of file random.c.

Referenced by random(), and srandom().