Cryptographic Co-Processor ATECC508A (Qwiic) Hookup Guide
Example 5: Random
This example shows how to use the Random Number Generator on the Sparkfun Cryptographic Co-processor. It will print random numbers once a second on the serial terminal at 115200.
This example only requires 1 Artemis and 1 co-processor. If you just completed example 4, you can choose to use Alice or Bob. This example helps set the stage for Example 6, so it's a good idea to check it out and see how the ATECC508A does random numbers - particularly its ability to create 32 bytes of random data!
Note, this chip is a bit more capable than the built-in Arduino function random()
.
random(max)
random(min, max)
It has a basic random(min, max)
. This will return a random number of type long.
Note, it works very similarly to the built-in Arduino random()
function, you can send it a single argument as a max, or you can send it two (as min and max).
It also has the following 3 other functions that can be useful in other applications.
getRandomByte()
getRandomInt()
getRandomLong()
Each of these functions return a random number of the type written into the name.
And lastly...
updateRandom32Bytes()
will create 32 bytes of random data and store it inatecc.random32Bytes[]
.
After calling updateRandom32Bytes()
then your random 32 bytes of data are available at a public variable
within the library instance. If your instance was named atecc
as in the SparkFun examples,
this array would be atecc.random32Bytes[]
. This can be useful as a challenge or time-to-live-token (aka NONCE
) to send to another device.