Teensy4.x Entropy library documentation?

Slabshaft

Member
I'm trying to use a random number generator for an audio sequencer using the latest Entropy library and a Teensy 4.0. Everything compiles and appears to work, but simply using Entropy.random(0,15); for a 16-step sequence appears to repeat every 64 numbers. Does this library use a seed function? How should this library be used to improve the randomness, assuming I'm looking for uniform distribution? Also, it looks like there's a normal distribution method Entropy.rnorm(mean, stdv) in there as well, which could be fun to use! But I can't seem to find the documentation for the latest library. Does anyone have some links that could help educate me on the use of the newest Entropy library for a T4.x or at least show me where to find the header file (I'm using PlatformIO)? I read something about a hardware true random number generator which I would love to play around with! Thanks for any tips!
 
but simply using Entropy.random(0,15); for a 16-step sequence appears to repeat every 64 numbers.

I tried to reproduce this problem with the following code.

Code:
#include <Entropy.h>

void setup() {
  Entropy.Initialize();
}

void loop() {
  for (int i=0; i < 64; i++) {
    Serial.print(Entropy.random(0, 15));
    Serial.print(",");
  }
  Serial.println();
}

Here's the result I see in the serial monitor.

sc.jpg

Every line of 64 numbers looks very different to me. It also generates very different data each time I run it.


Does this library use a seed function? How should this library be used to improve the randomness, assuming I'm looking for uniform distribution?

Entropy uses the hardware random number generator, so you are supposed to get truly random numbers.

Any chance you forgot to use Entropy.Initialize(); in your setup() function?

If it still won't work, please try running that tiny test program with Arduino. If it works in Arduino but not in PlatformIO, maybe report the issue to PlatformIO.
 
Just for ref - playing with Multi Serial did a count of Entropy results for values :: Entropy.random(0, 15)
This is output from SerialUSB1 - Let it run on two T_4.1's let it run for 1 second and print the first number on each row for the second - then add those to the full run accumulation:
Code:
------------
81	9983411
73	9987762
74	9982774
94	9985073
83	9987729
86	9987859
73	9988031
84	9986454
86	9990200
99	9982778
72	9982688
83	9984883
68	9985951
82	9980222
78	9983961

and second T_4.1:
Code:
------------
75	9954582
77	9956504
86	9953401
81	9953565
74	9953762
93	9960052
82	9949195
77	9956079
78	9957814
89	9955721
77	9955418
69	9955837
76	9954869
102	9956544
80	9954209
 
I've played with Entrophy to try to generate random hashes. I generated 10 of them in a row. Then I restarted my Teensy and did the same thing. 8 out of 10 were the exact same as the previous time.
Is there a way to truly generate random hashes every time?
 
Is there a repository on github for the Teensy-specific Entropy library? I can't find the source anywhere except installed as part of Teensyduino.
 
I can't find the source anywhere except installed as part of Teensyduino
Found this document on Github.

Nevermind, the document is already on your disk at C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Entropy\docs\manual.pdf.
Couldn't find the Entropy library on Github either.

Paul
 
Last edited:
Back
Top