@circom:field.rand
Generate a uniformly random BN254 field element (rejection-sampled, no modulo bias) for secrets, trapdoors and commitment salts.
⚗️ Experimental — available at next.evmcrispr.com.
Returns: number
Syntax
Section titled “Syntax”@circom:field.randExamples
Section titled “Examples”# Random secret and its Poseidon commitmentset $secret @circom:field.rand()print "Commitment:" @circom:poseidon($secret)- Uses rejection sampling over
crypto.getRandomValues, so values are uniform over the field (no modulo bias). - Each evaluation produces a fresh value — bind it with
setif you need to reuse it.
See Also
Section titled “See Also”- @circom:poseidon — commit to the generated secret