random.c File Reference

Thread safe random functions. More...

#include "config.h"
#include "util/random.h"
#include "util/log.h"
#include <time.h>

Macros

#define MAX_VALUE   0x7fffffff
 Max random value. More...
 

Functions

void ub_randfree (struct ub_randstate *s)
 Delete the random state. More...
 

Detailed Description

Thread safe random functions.

Similar to arc4random() with an explicit initialisation routine.

The code in this file is based on arc4random from openssh-4.0p1/openbsd-compat/bsd-arc4random.c That code is also BSD licensed. Here is their statement:

Copyright (c) 1996, David Mazieres dm@uu.nosp@m.n.or.nosp@m.g Copyright (c) 2008, Damien Miller djm@o.nosp@m.penb.nosp@m.sd.or.nosp@m.g

Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Macro Definition Documentation

◆ MAX_VALUE

#define MAX_VALUE   0x7fffffff

Max random value.

Similar to RAND_MAX, but more portable (mingw uses only 15 bits random).

Function Documentation

◆ ub_randfree()

void ub_randfree ( struct ub_randstate *  state)

Delete the random state.

Parameters
stateto delete.

Referenced by daemon_delete(), libworker_delete_env(), rnd_test(), tcpid_test(), ub_ctx_create(), ub_ctx_create_nopipe(), and worker_delete().