Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:45 04 Dec 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Understanding MMBASIC Random Numbers- Pico2040 Especially

Author Message
jwettroth

Regular Member

Joined: 02/08/2011
Location: United States
Posts: 97
Posted: 05:59am 03 Dec 2026
Copy link to clipboard 
Print this post

I'm working on an MP-3 player with a DF Player and Pico 1 running V5.08 (see previous thread "Autorun troubles...").  I have a new mystery that I haven't fully analyzed regarding the operation of the Random number function on the PICO 1.  I know the PICO 2 has sophisticated hardware for random number generation.  Let's leave this aside this for now.  I'm using a PICO 1- 2040.

My little MP-3 player seeds the random number generator with the current timer value after startup.  It queries the number of tracks (NUMTRKS%) on the uSD installed in the DF player.  It then generates random track number by calculating:  Nexttrack%= Int(RND() * (NUMTRACKS% + 1)).  This seems to work well enough for the first song- its seldom the same song as previous starts.  What I think I'm experiencing, subjectively is getting less than random results with this setup.  I only seed the random num generator at the beginning and the timer has a bit of variability due to the vagaries of startup.

Is this all my imagination?  Its seem certain songs play much more often than others.  And sometimes a song that was played shortly before a shutdown, will play again.  I'll do some testing if I can (its difficult) but is there a better way to seed the RNG short of going to a PICO 2?  Should I reseed it periodically?  I will run a distribution test overnight but a lot of what I'm seeing is after power cycling, etc not just a straight distribution.  Is there some systematic error that I'm missing?  It doesn't matter for the toddler audience that this system is intended for but its a puzzle if I wanted to make one of these gadgets for myself.

Any ideas welcome.
John Wettroth
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3479
Posted: 07:44am 03 Dec 2026
Copy link to clipboard 
Print this post

I observed a similar effect with a random track player about a year ago (for Frank N. Furter's Christmas Bells reverse engineering project).
Using a Pico 2 made no difference so studied up on the subject and found the problem is the human brain. It is wired to see patterns in everything so even genuinely random numbers don't look random. Repeats are normal in a set of random numbers.

I wound up generating a play list that excluded any track number already in the list by repeating the random selection until a new number appeared. This results in a play list that looks more random than it is. Each track gets played once only.
 
jwettroth

Regular Member

Joined: 02/08/2011
Location: United States
Posts: 97
Posted: 08:42am 03 Dec 2026
Copy link to clipboard 
Print this post

Phil,
You universally have very solid answers on this forum.  Much appreciated.  I think I'll implement your idea for my player.  I am sure you're right.

I did a test tonight where I chose 5 songs and kept hitting the random play button until I heard them, it was in line with what the statistics should be.  

Thanks
John Wettroth
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 3479
Posted: 11:33am 03 Dec 2026
Copy link to clipboard 
Print this post

Here is the randomizer from that program.
'Randomizer - Track 0 (bell test) first then 22 tracks in random order
Dim integer TrackNo(22), tk, m, n
n=1
Do
  TrackNo(n) = Cint(Rnd * 21)+1
  For m=0 To n-1
    If TrackNo(n)=TrackNo(m) Then tk = 1
  Next
  If tk=0 Then Inc n
  tk=0
Loop Until n=23

Print : Print "Play List - track numbers " : Math V_Print TrackNo()
Print
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4409
Posted: 03:39pm 03 Dec 2026
Copy link to clipboard 
Print this post

Something similar happened with er, the iPod I think it was.  They made it non-random but random-like to fool the humans.

John
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026