NeoMutt  2023-05-17-16-g61469c
Teaching an old dog new tricks
DOXYGEN
random.h File Reference

Random number/string functions. More...

#include <stddef.h>
#include <stdint.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 118 of file random.c.

119{
120 uint32_t num = 0;
121
122 if (mutt_randbuf(&num, sizeof(num)) < 0)
123 mutt_exit(1);
124 return num;
125}
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:241
static int mutt_randbuf(void *buf, size_t buflen)
Fill a buffer with randomness.
Definition: random.c:56
+ 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 131 of file random.c.

132{
133 uint64_t num = 0;
134
135 if (mutt_randbuf(&num, sizeof(num)) < 0)
136 mutt_exit(1);
137 return num;
138}
+ 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 104 of file random.c.

105{
106 uint8_t *p = (uint8_t *) buf;
107
108 if (mutt_randbuf(p, buflen) < 0)
109 mutt_exit(1);
110 for (size_t pos = 0; pos < buflen; pos++)
111 p[pos] = Base32[p[pos] % 32];
112}
static const unsigned char Base32[]
Base 32 alphabet.
Definition: random.c:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function: