aboutsummaryrefslogtreecommitdiffstats
path: root/vdslib/src/vespa/vdslib/state/random.h
blob: 28efcc3389309128c8117c6a0de802b5eef63c1c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/vespalib/util/random.h>

namespace storage::lib {

/**
 * Random number generator. Compatible with java.util.Random
 * Calls PRNG from vespalib, but throws away the first number generated.
 */
class RandomGen : public vespalib::RandomGen {
public:
    RandomGen(int32_t seed) : vespalib::RandomGen(seed) {
        nextDouble();
    };

    /**
     * Construct a random number generator with an auto-generated seed
     */
    RandomGen() : vespalib::RandomGen() {}

    /**
     * Reset the seed
     */
    void setSeed(int32_t seed) {
        vespalib::RandomGen::setSeed(seed);
        nextDouble();
    }
};

}