Rename rand64() to _rand64()

This commit is contained in:
Justine Tunney 2022-10-10 04:12:06 -07:00
parent c424352a0a
commit 7ae556463a
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
52 changed files with 141 additions and 139 deletions

View file

@ -86,7 +86,7 @@ int tmpfd(void) {
*p++ = '.';
}
for (i = 0; i < 10; ++i) {
x = rand64();
x = _rand64();
for (j = 0; j < 6; ++j) {
p[j] = "0123456789abcdefghijklmnopqrstuvwxyz"[x % 36];
x /= 36;

View file

@ -63,7 +63,7 @@ int ResolveDns(const struct ResolvConf *resolvconf, int af, const char *name,
if (!resolvconf->nameservers.i) return 0;
bzero(&h, sizeof(h));
rc = ebadmsg();
h.id = rand64();
h.id = _rand64();
h.bf1 = 1; /* recursion desired */
h.qdcount = 1;
q.qname = name;

View file

@ -24,17 +24,17 @@
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/dns/consts.h"
#include "libc/dns/dns.h"
#include "libc/dns/dnsheader.h"
#include "libc/dns/dnsquestion.h"
#include "libc/dns/resolvconf.h"
#include "libc/intrin/bits.h"
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"
#include "libc/stdio/rand.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/af.h"
#include "libc/sysv/consts/ipproto.h"
@ -65,7 +65,7 @@ int ResolveDnsReverse(const struct ResolvConf *resolvconf, int af,
if (!resolvconf->nameservers.i) return 0;
bzero(&h, sizeof(h));
rc = ebadmsg();
h.id = rand64();
h.id = _rand64();
h.bf1 = 1; /* recursion desired */
h.qdcount = 1;
q.qname = name;

View file

@ -29,7 +29,7 @@
* tracked by a global variable which is updated at fork(). The only
* exception is when the process is vfork()'d in which case a system
* call shall be issued. This optimization helps make functions like
* rand64() fork-safe, however it could lead to race conditions in
* _rand64() fork-safe, however it could lead to race conditions in
* programs that mix fork() with threads. In that case, apps should
* consider using `sys_getpid().ax` instead to force a system call.
*

View file

@ -46,7 +46,7 @@ static struct {
* @threadsafe
* @vforksafe
*/
uint64_t rand64(void) {
uint64_t _rand64(void) {
void *p;
uint128_t s;
if (__threaded) pthread_spin_lock(&g_rand64.lock);

View file

@ -29,7 +29,7 @@
* double x = _real1(lemur64()); // make float on [0,1]-interval
*
* If you want a fast pseudorandom number generator that seeds itself
* automatically on startup and fork() then consider rand64(). If you
* automatically on startup and fork(), then consider _rand64. If you
* want true random data then consider rdseed, rdrand, and getrandom.
*
* @return 64 bits of pseudorandom data
@ -37,7 +37,7 @@
* @note this function takes at minimum 1 cycle
* @note this function passes bigcrush and practrand
* @note this function is not intended for cryptography
* @see rand64(), rngset(), _real1(), _real2(), _real3()
* @see _rand64(), rngset(), _real1(), _real2(), _real3()
*/
uint64_t lemur64(void) {
static uint128_t s = 2131259787901769494;

View file

@ -42,7 +42,7 @@ char *mkdtemp(char *template) {
int i, j, n;
if ((n = strlen(template)) >= 6 && !memcmp(template + n - 6, "XXXXXX", 6)) {
for (i = 0; i < 10; ++i) {
x = rand64();
x = _rand64();
for (j = 0; j < 6; ++j) {
template[n - 6 + j] = "0123456789abcdefghijklmnopqrstuvwxyz"[x % 36];
x /= 36;

View file

@ -77,7 +77,7 @@ static uint64_t g_mkostemps_reseed;
dontdiscard int mkostempsm(char *template, int suffixlen, unsigned flags,
int mode) {
int fd;
if (g_mkostemps_reseed++ % RESEED == 0) g_mkostemps_rand = rand64();
if (g_mkostemps_reseed++ % RESEED == 0) g_mkostemps_rand = _rand64();
fd = mkostempsmi(template, suffixlen, flags, &g_mkostemps_rand, mode, open);
STRACE("mkostempsm([%#s], %'d, %#x, %#o) → %d% m", template, suffixlen, flags,
mode, fd);

View file

@ -35,7 +35,7 @@
*
* @note this function does well on bigcrush and practrand
* @note this function is not intended for cryptography
* @see lemur64(), rand64(), rdrand()
* @see lemur64(), _rand64(), rdrand()
*/
int rand(void) {
return KnuthLinearCongruentialGenerator(&g_rando) >> 33;

View file

@ -23,7 +23,7 @@ long random(void);
void srandom(unsigned);
uint64_t lemur64(void);
uint64_t rand64(void);
uint64_t _rand64(void);
uint64_t vigna(void);
uint64_t vigna_r(uint64_t[hasatleast 1]);
void svigna(uint64_t);

View file

@ -16,8 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/asmflag.h"
#include "libc/errno.h"
#include "libc/intrin/asmflag.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/stdio/rand.h"
#include "libc/sysv/consts/grnd.h"
@ -38,7 +38,7 @@ static dontinline uint64_t rdrand_failover(void) {
r = 0;
f = 0;
} else {
return rand64();
return _rand64();
}
}
}
@ -59,7 +59,7 @@ static dontinline uint64_t rdrand_failover(void) {
* @note this function could block a nontrivial time on old computers
* @note this function is indeed intended for cryptography
* @note this function takes around 300 cycles
* @see rngset(), rdseed(), rand64()
* @see rngset(), rdseed(), _rand64()
* @asyncsignalsafe
* @vforksafe
*/

View file

@ -34,7 +34,7 @@
* @note this function could block a nontrivial time on old computers
* @note this function is indeed intended for cryptography
* @note this function takes around 800 cycles
* @see rngset(), rdrand(), rand64()
* @see rngset(), rdrand(), _rand64()
* @asyncsignalsafe
* @vforksafe
*/

View file

@ -46,7 +46,7 @@ static uint64_t g_vigna;
* rngset(buf, sizeof(buf), vigna, 0);
*
* If you want a fast pseudorandom number generator that seeds itself
* automatically on startup and fork() then consider rand64(). If you
* automatically on startup and fork(), then consider _rand64. If you
* want true random data then consider rdseed, rdrand, and getrandom.
*
* @return 64 bits of pseudorandom data