User Random Number generation

Hi
Can I generate my userRandomNumber on-chain that I need to pass to Entropy provider? Are there any security consideration regarding that?

  function requestRandomNumber(bytes32 userRandomNumber) external payable {
    // Get the default provider and the fee for the request
    address entropyProvider = entropy.getDefaultProvider();
    uint256 fee = entropy.getFee(entropyProvider);
 
    // Request the random number with the callback
    uint64 sequenceNumber = entropy.requestWithCallback{ value: fee }(
      entropyProvider,
      userRandomNumber
    );
    // Store the sequence number to identify the callback request
  }```

Pyth Entropy generates a truly random number by hashing two inputs:

  1. A random number provided by the user
  2. A random number provided by the Entropy provider

This combination ensures that the final output is truly random and cannot be predicted or manipulated by a single party.

Even though the Entropy provider supplies a secure random value, we recommend not generating the user’s random number on-chain, as any value generated on-chain is inherently deterministic and could be predicted or exploited.

Instead, you can generate randomness off-chain — for example, using web3.js:

const userRandomNumber = web3.utils.randomHex(32);