inline LHaga random_ldouble (bajo LHaga = 0,0, alta LHaga = 1,0) { std :: uniform_real_distribution <LHaga> distribución (baja, alta); std :: mt19937 generador; std :: estática función <LHaga ()> FHaga = std :: bind (distribución, generador); volver FHaga (); } Inline número entero random_integer (entero bajo = 0, número entero alta = std :: numeric_limits <entero> :: max ()) { std :: uniform_int_distribution <entero> distribución (baja, alta); std :: mt19937 generador; std :: estática función <número entero ()> finteger = std :: bind (distribución, generador); volver finteger (); }
Para lograr conveniente después del trasplante, y para lograr x64 y x86 compilador no está dando, primero debe definir algunos tipos comunes.
Es necesario incluir el archivo de cabecera
#include <iostream> #include <fstream> #include <sstream> #include <string> #include <algoritmo> #include <iterador> #include <cctype> #include <vector> #include <iomanip> #include <funcional> # include <aleatorio> #include <math> #include <cassert>
tipo genérico, así como algunos macros útiles
typedef carbón INT8; //兼容char, int8_t, firmado carbón typedef uint8_t u_int8; typedef int16_t Int16; typedef uint16_t u_int16; typedef int32_t int32; typedef uint32_t u_int32; typedef int64_t Int64; typedef uint64_t u_int64; typedef largo doble LHaga; #define MAKEINT16 (x, y) ((u_int16) (((u_int8) (((u_int32) (x)) y 0xff)) | ((u_int16) ((u_int8) (((u_int32) (y)) y 0xff ))) << 8)) #define MAKEINT32 (x, y) ((u_int32) (((u_int16) (((u_int32) (x)) y 0xffff)) | ((u_int32) ((u_int16) ((( u_int32) (y)) y 0xffff))) << 16)) #define MAKEINT64 (x, y) ((u_int64) (((u_int32) (((u_int64) (x)) y 0xffffffff)) | ((u_int64 ) ((u_int32) (((u_int64) (y)) y 0xFFFFFFFF))) << 32)) #define LOWINT16 (l) ((u_int8) (((u_int16) (l)) y 0xff)) #define HIGHINT16 (l) ((u_int8) ( (((u_int16) (l)) >> 8) y #define HIGHINT32 (l) ((u_int16) ((((u_int32) (l)) >> 16) y 0xffff)) #define LOWINT64 (l) ((u_int32) (((u_int64) (l)) y 0xFFFFFFFF) ) #define HIGHINT64 (l) ((u_int32) ((((u_int64) (l)) >> 32) y 0xFFFFFFFF)) #define radianes (grados) ((M_PI / 180) * deg) grado #define (rad) ((180 / M_PI) * rad) #ifdef _WIN64 typedef __int64 firmado entero; typedef unsigned __int64 u_integer; #define MAKEINT (x, y) MAKEINT64 (x, y) HIGHINT #define (l) HIGHINT64 (l) #define LOWINT (l) LOWINT64 (l) #else typedef firmó __int32 número entero; typedef unsigned __int32 u_integer; #define MAKEINT (x, y) MAKEINT32 (x, y) #define HIGHINT (l) HIGHINT32 (l) #define LOWINT ( l) LOWINT32 (l) #endif inline LHaga max (a LHaga, LHaga b) { volver a> b? a: b; } inline min LHaga (a LHaga, LHaga b) { devolver un <b? a: b; }
Dos frecuentemente utiliza función aleatoria, no un pseudo-aleatoria, pero con nuevas funciones dentro de la función de C ++ verdaderamente aleatoria
inline LHaga random_ldouble (bajo LHaga = 0,0, alta LHaga = 1,0) { std :: uniform_real_distribution <LHaga> distribución (baja, alta); std :: mt19937 generador; std :: estática función <LHaga ()> FHaga = std :: bind (distribución, generador); volver FHaga (); } Inline número entero random_integer (entero bajo = 0, número entero alta = std :: numeric_limits <entero> :: max ()) { std :: uniform_int_distribution <entero> distribución (baja, alta); std :: mt19937 generador; std :: estática función <número entero ()> finteger = std :: bind (distribución, generador); volver finteger (); }
Puse el nombre de este archivo types.h, para facilitar programas de 32 bits y 64 bits de propósito general suscripciones futuras. Y pongo el código de la llave en un interior-lib completa (cuando se crea un nuevo proyecto, seleccionar un lib estática en la línea), fácil de llamar a otros artículos. Resultados como se muestra