2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 This pseudorandom number generator is based on ref_xorshift128plus,
19 as implemented by reference_xorshift.h, which has been obtained
20 from https://sourceforge.net/projects/xorshift-cpp/
22 The licensing terms for reference_xorshift.h are reproduced below.
24 // Written in 2014 by Ivo Doko (ivo.doko@gmail.com)
25 // based on code written by Sebastiano Vigna (vigna@acm.org)
26 // To the extent possible under law, the author has dedicated
27 // all copyright and related and neighboring rights to this
28 // software to the public domain worldwide. This software is
29 // distributed without any warranty.
30 // See <http://creativecommons.org/publicdomain/zero/1.0/>.
36 #include <rte_cycles.h>
42 static void random_init_seed(struct random *random)
44 random->state[0] = rte_rdtsc();
45 random->state[1] = rte_rdtsc();
48 static uint64_t random_next(struct random *random)
50 const uint64_t s0 = random->state[1];
51 const uint64_t s1 = random->state[0] ^ (random->state[0] << 23);
53 random->state[0] = random->state[1];
54 random->state[1] = (s1 ^ (s1 >> 18) ^ s0 ^ (s0 >> 5)) + s0;
55 return random->state[1];
58 #endif /* _RANDOM_H_ */