Как генерировать случайные 64 бит с увеличением случайных

StackOverflow https://stackoverflow.com/questions/3490461

  •  28-09-2019
  •  | 
  •  

Вопрос

Я пытаюсь сгенерировать случайное 64-битное целое число без знака, используя повышение случайных, но я получаю отказ от утверждения Upply_int.

struct timeval tv;
boost::mt19937 randGen(tval.tv_usec);
boost::uniform_int<> uInt64Dist(0, std::numeric_limits<uint64_t>::max());
boost::variate_generator<boost::mt19937&, boost::uniform_int<> > getRand(randGen, uInt64Dist);
uint64_t clock_seq_= getRand();

Вот что получает вывод в строке 3.

main:/usr/include/boost/random/uniform_int.hpp:48: boost::uniform_int<IntType>::uniform_int(IntType, IntType) [with IntType = int]: Assertion `min_arg <= max_arg' failed.

Редактировать: На основе ваших ответов я пытался указать размер с ниже:

boost:uniform_int<uint64_t> ....

Но я получаю следующую ошибку компиляции:

spec.cpp: In member function ‘void Specifier::initialize()’:
spec.cpp:58: error: no matching function for call to ‘boost::variate_generator<boost::mt19937&, boost::uniform_int<int> >::variate_generator(boost::mt19937&, boost::uniform_int<long unsigned int>&)’
/usr/include/boost/random/variate_generator.hpp:97: note: candidates are: boost::variate_generator<Engine, Distribution>::variate_generator(Engine, Distribution) [with Engine = boost::mt19937&, Distribution = boost::uniform_int<int>]
/usr/include/boost/random/variate_generator.hpp:87: note:                 boost::variate_generator<boost::mt19937&, boost::uniform_int<int> >::variate_generator(const boost::variate_generator<boost::mt19937&, boost::uniform_int<int> >&)
make: *** [spec.o] Error 1

Редактировать: ОК, пропустил второй экземпляр Boost :: Upply_int. Однажды я оба, все, все идут.

Это было полезно?

Решение

uniform_int по умолчанию int как тип значения. Вместо этого используйте следующее:

boost::uniform_int<uint64_t> ...

То же самое касается следующей линии:

boost::variate_generator<boost::mt19937&, boost::uniform_int<uint64_t> > ...

Другие советы

Вам нужно указать в своей декларации boost::uniform_int<> Что вы используете 64 бит целочисленного типа. Иначе это по умолчанию к 32-битному типу.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top