NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
random.h File Reference

Random number/string functions. More...

#include <stdint.h>
#include <stddef.h>
+ Include dependency graph for random.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

uint32_t mutt_rand32 (void)
 Create a 32-bit random number. More...
 
uint64_t mutt_rand64 (void)
 Create a 64-bit random number. More...
 
void mutt_rand_base32 (char *buf, size_t buflen)
 Fill a buffer with a base32-encoded random string. More...
 

Detailed Description

Random number/string functions.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file random.h.

Function Documentation

◆ mutt_rand32()

uint32_t mutt_rand32 ( void  )

Create a 32-bit random number.

Return values
numRandom number

Definition at line 117 of file random.c.

118 {
119  uint32_t num = 0;
120 
121  if (mutt_randbuf(&num, sizeof(num)) < 0)
122  mutt_exit(1);
123  return num;
124 }
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:279
static int mutt_randbuf(void *buf, size_t buflen)
Fill a buffer with randomness.
Definition: random.c:55
+ Here is the call graph for this function:

◆ mutt_rand64()

uint64_t mutt_rand64 ( void  )

Create a 64-bit random number.

Return values
numRandom number

Definition at line 130 of file random.c.

131 {
132  uint64_t num = 0;
133 
134  if (mutt_randbuf(&num, sizeof(num)) < 0)
135  mutt_exit(1);
136  return num;
137 }
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:279
static int mutt_randbuf(void *buf, size_t buflen)
Fill a buffer with randomness.
Definition: random.c:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_rand_base32()

void mutt_rand_base32 ( char *  buf,
size_t  buflen 
)

Fill a buffer with a base32-encoded random string.

Parameters
bufBuffer for result
buflenLength of buffer

Definition at line 103 of file random.c.

104 {
105  uint8_t *p = (uint8_t *) buf;
106 
107  if (mutt_randbuf(p, buflen) < 0)
108  mutt_exit(1);
109  for (size_t pos = 0; pos < buflen; pos++)
110  p[pos] = base32[p[pos] % 32];
111 }
static const unsigned char base32[]
Definition: random.c:46
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:279
static int mutt_randbuf(void *buf, size_t buflen)
Fill a buffer with randomness.
Definition: random.c:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function: