1 /** Most people who want UUIDs will generate small numbers of them (maybe a
2   * few hundred thousand) and not require a huge amount of uniqueness (just
3   * for this one application). This module provides a convenient way to obtain
4   * that behavior.
5   *
6   * To streamline your usage, this module publicly imports Uuid, so you can
7   * import this module alone.
8   *
9   * To use this module, just:
10   * ---
11   * import ocean.util.uuid.RandomGen;
12   *
13   * Uuid id = randUuid.next;
14   * ---
15   *
16   * Copyright:
17   *     Copyright (c) 2009-2016 dunnhumby Germany GmbH.
18   *     All rights reserved.
19   *
20   * License:
21   *     Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
22   *     Alternatively, this file may be distributed under the terms of the Tango
23   *     3-Clause BSD License (see LICENSE_BSD.txt for details).
24   *
25   */
26 module ocean.util.uuid.RandomGen;
27 
28 public import ocean.util.uuid.Uuid;
29 import ocean.math.random.Twister;
30 
31 /** The default random UUID generator. You can set this if you need to generate
32   * UUIDs in another manner and already have code pointing to this module.
33   *
34   * This uses a unique PRNG instance. If you want repeatable results, you
35   * should inject your own UUID generator and reseed it as necessary:
36   * ---
37   * auto rand = getRand();
38   * randUuid = new RandomGen!(typeof(rand))(rand);
39   * doStuff();
40   * rand.reseed();
41   * ---
42   *
43   * The default PRNG is the Mersenne twister. If you need speed, KISS is about
44   * 30 times faster. I chose the Mersenne twister because it's reasonably fast
45   * (I can generate 150,000 per second on my machine) and has a long period.
46   * The KISS generator can produce 5 million per second on my machine.
47   */
48 UuidGen randUuid;
49 
50 static this ()
51 {
52         Twister rand;
53         rand.seed;
54         randUuid = new RandomGen!(Twister)(rand);
55 }
56