Parece que cuando le doy a la consulta de Oracle un N de 4, siempre devuelve un número de 19 dígitos, esto podría ser una coincidencia, pero creo que no. ¿Qué sucede si realmente quiero un número entre, digamos, 0 y 10 * 10 ^ 18?
es posible? Así es como se ve mi Oraclize ahora:
oraclize_setProof(proofType_Ledger); // sets the Ledger authenticity proof
uint N = 4; // number of random bytes we want the datasource to return
uint delay = 0; // number of seconds to wait before the execution takes place
uint callbackGas = 200000; // amount of gas we want Oraclize to set for the callback function
bytes32 queryId = oraclize_newRandomDSQuery(delay, N, callbackGas);
Y en el __callBack
uint maxRange = totalEth -1; // deduct one so that when one gets added later it cant be bigger than the total eth.
randomNumber = (uint(sha3(_result)) % maxRange) + 1 // this is an efficient way to get the uint out in the [1, maxRange] range
Parece que está utilizando los bytes aleatorios para generar un número entre 1
y maxRange
, inclusive. Si desea un número entre 0
y 10**18
, configúrelo maxRange
y 10**18
suéltelo + 1
en su código.
Pero tenga en cuenta que 4 bytes aleatorios no son suficiente entropía para generar números en ese rango . 4 bytes le da solo 2**32
valores diferentes, que es 4,294,967,296
. Esto es mucho más pequeño que 10**18
. Necesitarás usar 8 bytes . ( log2(10^18) ~= 60 bits
.)
jaspe
usuario19510