NeoMutt  2024-12-12-14-g7b49f7
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 123 of file random.c.

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

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