Hi, need help
Is there a way to create unique random number between range in solidity?
Jan 20, 2023, 7:17 AM
The best way to do this is using chainlink oracles, or even better generating the random number off-chain
Solidity doesn't have an inbuilt random number generator like other languages
Jan 20, 2023, 7:28 AM
I am using chainlink, but it won't me random number in range everytime
currently I'm generating a index using chainlink and using that number to select a value from array, and then pop that number from the array.
But this method is quite high on gas, is there any other way to this?
But this method is quite high on gas, is there any other way to this?
Jan 20, 2023, 7:30 AM
Not really, randomness doesnt exist in Math
You could do some random calculations like timestamp/blockNumber/walletNounce or whatever
If you only want to fish out an address of an array once an hour or so
But as soon as you allow transactions from users this is not safe
Jan 20, 2023, 7:34 AM
yeah exactly
Jan 20, 2023, 7:34 AM
Why dont you do it offchain
Jan 20, 2023, 7:35 AM
I need to pas it as tokenId to in ERC721 contract, passing token Id to an NFT contract is not the best practice
Jan 20, 2023, 7:36 AM
Apply bounds to your received random num
Jan 20, 2023, 7:42 AM
Already did, that's how i'm generating index between array length
Jan 20, 2023, 7:43 AM
Then what's the issue?
Jan 20, 2023, 7:44 AM
this method is very expensive on gas
It works fine, but very expensive
Jan 20, 2023, 8:32 AM
Huh how is that expensive? All you're doing is applying a mod (possibly an addition too).
Jan 20, 2023, 8:35 AM
i have to call it number of times
example if I want to mint 5 NFT, I need generate random index 5 times
Jan 20, 2023, 8:36 AM
Well, do repeated hashing and generate any number of random words you want. I still don't see the expensive part
Jan 20, 2023, 8:40 AM
you can call chainlink asking multiple random numbers in tx
then apply the modulo and done
https://twitter.com/devanoneth/status/1616253670860984321?t=3AmZ44bgUiC1lBWTtD_0yg&s=35
Jan 20, 2023, 8:48 AM