开发者

How hard is it to create a not-so-random number generator? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

Backstory:

So I was driving to band practice this evening. My car has a USB port where you can plug in a USB stick with MP3 files on it and the stereo will play them. I have about 100 MP3s on my stick so I pushed the 'Random' button. So from here to band practice, it played:

Then on the way home, it played

  • Track 16
  • Track 27
  • Track 33

And then I stopped at the petrol station. I filled up, got back in the car and the stereo fired up again. It played

  • Track 22
  • Track 45
  • Track 4
  • Track 11
  • Track 87

I thought, WTF? What's with this 'random' generator? What are they using as a seed, if not time? Is a car stereo so memory-tight that it can't even use the C stdlib? Does anyone know how this kind of thing happens?


Without looking at the code of the music player it's hard to say. Some thoughts:

  1. It may be that it created a random playlist, then started the playlist again at the beginning. E.g., a random sequence which it then repeated, as opposed to independently coming up with the same sequence from its random number generator twice.
  2. Or, of course, it is using time as its seed and its clock is messed up and sometimes reading 0 or something, resulting in the repeated sequence.
  3. Or (with apologies) observational error. :-)


MP3 players tend to generate a random playlist when you select the random option, then play the same playlist.

The only 'random' part is that the playlist changes each time you re-set the 'random' option.

As an example, the iPod shuffle mp3 player has a functionality that allows you to re-shuffle the songs in order to generate a new 'random' playlist.


It's important to remember that without good statistical analysis our psychology lends to the fact that we spot patterns even when they don't exist (for all intents and purposes).

For example, if you had 10 songs on your iPod, there is a high chance when you play all ten songs in 2 sets, that there will be tracks next to each other in both sets. Our brains are wired to spot and notice that.

If the pattern you describe is true, then yes, they probably messed up their code a little. Perhaps the internal system time resets every time the device is powered off, so when you turn it on by pressing 'play all' instead of 'switch on' then 'play all' it might play the same tracks in the same order. Or perhaps time isn't used as a seed.

Or, perhaps (unlikely) it is random. A truly random sequence will repeat orders eventually, especially in such a small set of 100 it's not beyond the realms of possibility you will see repeats in subsets of the data.


It may be that the embedded device controlling the randomization doesn't have a clock. Perhaps it uses the number of tracks as seed or something similar.

If you don't have some external source for random seeds, such as readings from a clock, the software will, when all it's memory is reset, behave deterministically each time it is started.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜