mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-08 14:22:31 -04:00
Merging branches/v0.5-peernet/libbitdht (Merging r4237 through r4353 into '.')
There are many significant improvements to the DHT here. See commit logs on v0.5-peernet branch for details. This is not the final merge, but brings over the majority of expected v0.5-peernet/libbitdht changes git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4354 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f517442989
commit
fff40eceac
40 changed files with 6843 additions and 746 deletions
71
libbitdht/src/util/bdrandom.h
Normal file
71
libbitdht/src/util/bdrandom.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
#ifndef BITDHT_UTILS_BDRANDOM_H
|
||||
#define BITDHT_UTILS_BDRANDOM_H
|
||||
|
||||
|
||||
/****************************************************************
|
||||
* libbitdht is distributed under the following license:
|
||||
*
|
||||
* Copyright (C) 2010 Cyril Soler <csoler@users.sourceforge.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
/* This Source Code is basically a direct copy of libretroshare's RsRandom.
|
||||
* the function names have just been renamed. drbob
|
||||
*/
|
||||
|
||||
|
||||
// bdRandom contains a random number generator that is
|
||||
// - thread safe
|
||||
// - system independant
|
||||
// - fast
|
||||
// - cryptographically safe
|
||||
//
|
||||
// The implementation is adapted from the Mersenne Twister page of Wikipedia.
|
||||
//
|
||||
// http://en.wikipedia.org/wiki/Mersenne_twister
|
||||
|
||||
#include <vector>
|
||||
#include "util/bdthreads.h"
|
||||
|
||||
class bdRandom
|
||||
{
|
||||
public:
|
||||
static uint32_t random_u32() ;
|
||||
static uint64_t random_u64() ;
|
||||
static float random_f32() ;
|
||||
static double random_f64() ;
|
||||
|
||||
static bool seed(uint32_t s) ;
|
||||
|
||||
static std::string random_alphaNumericString(uint32_t length) ;
|
||||
|
||||
private:
|
||||
static bdMutex rndMtx ;
|
||||
|
||||
static const uint32_t N = 624;
|
||||
static const uint32_t M = 397;
|
||||
|
||||
static const uint32_t MATRIX_A = 0x9908b0dfUL;
|
||||
static const uint32_t UMASK = 0x80000000UL;
|
||||
static const uint32_t LMASK = 0x7fffffffUL;
|
||||
|
||||
static void locked_next_state() ;
|
||||
static uint32_t index ;
|
||||
static std::vector<uint32_t> MT ;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue