NeoMutt  2024-03-23-147-g885fbc
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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

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

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

uint64_t mutt_rand64 ( void  )

Create a 64-bit random number.

Return values
numRandom number

Definition at line 122 of file random.c.

123{
124 uint64_t num = 0;
125
126 if (mutt_randbuf(&num, sizeof(num)) < 0)
127 mutt_exit(1); // LCOV_EXCL_LINE
128 return num;
129}
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:268
static int mutt_randbuf(void *buf, size_t buflen)
Fill a buffer with randomness.
Definition: random.c:57
+ 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 105 of file random.c.

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