1 .\" $NetBSD: randomid.3,v 1.6 2005/12/26 19:40:14 perry Exp $
3 .\" Copyright (C) 2006 The NetBSD Foundation
4 .\" All rights reserved.
6 .\" Copyright (C) 2003 WIDE Project.
7 .\" All rights reserved.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
17 .\" 3. Neither the name of the project nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 .Nd provide pseudo-random data stream without repetitions
45 .Fn randomid "randomid_t ctx"
47 .Fn randomid_new "int bits" "long timeo"
49 .Fn randomid_delete "randomid_t ctx"
53 function provides pseudo-random data stream,
54 which is guaranteed not to generate the same number twice during
57 is the context which holds internal state for the random number generator.
59 To initialize a context,
63 specifies the bitwidth of the value generated by
65 Currently 32, 20, and 16 are supported.
67 specifies the reinitialization interval in seconds.
70 .Dv RANDOMID_TIMEO_MIN .
72 returns a dynamically-allocated memory region allocated by
81 The same number may appear after two reinitialization events of the internal state,
83 Reinitialization happens when the random number generator cycle is exhausted,
86 seconds have passed since the last reinitialization.
89 configured to generate 16 bit data stream will reinitialize its internal state
97 therefore the same data will not appear until after 30000 calls to
107 determines the data stream generated by
110 must be allocated per data stream
111 .Pq such as a specific data field .
112 It must not be shared among multiple data streams with different usage.
115 .Bd -literal -offset indent
116 #include \*[Lt]stdio.h\*[Gt]
117 #include \*[Lt]sys/types.h\*[Gt]
118 #include \*[Lt]randomid.h\*[Gt]
123 static randomid_t ctx = NULL;
126 ctx = randomid_new(16, (long)3600);
127 return randomid(ctx);
135 on error and sets the external variable
142 The pseudo-random data stream generator was designed by Niels Provos for
144 IPv4 fragment ID generation.
146 is a generalized version of the generator, reworked by Jun-ichiro itojun Hagino,
147 and was introduced in