CRYPTO NEWS

How to get gas price in Solidity smart contract?

I’m on the most recent version on solidity.

"tx.gas" and "tx.gasprice" both dont work. They error with "Member "gas" not found or not visible after argument-dependent lookup in tx".

How do I get the gasPrice in the contract?

Bits of entropy needed to choose a random element from a list?

Suppose I want to choose a random element from a list of size $2^n$, for any integer $n$. (Here, random is to mean an equal probability of selecting every item.) My intuition says I’d need $n$ bits of entropy. For example, for a list of size 64, I’d need 6 bits of entropy. However, how::Listen

Suppose I want to choose a random element from a list of size $2^n$, for any integer $n$. (Here, random is to mean an equal probability of selecting every item.) My intuition says I’d need $n$ bits of entropy. For example, for a list of size 64, I’d need 6 bits of entropy.

However, how many bits of entropy would I need to choose a random element from a list that’s sized something other than $2^n$? For example, for a list of size 3, or 10?

My intuition says that I’d need to find $n$ such that $2^n$ is a multiple of list size, to ensure equal probability of selecting every item. (This is true for all lists sized $2^n$.) However, that doesn’t seem to work in practice: there does not appear to be any $n$ such that $2^n$ that divides evenly into 3 or 10.

How to get gas price in Solidity smart contract?

Shopping cart
There are no products in the cart!
Continue shopping
0