Category Archives: Thoughts on the World

Random? That’s a Coincidence…

A randomly selected image this morning - my old VW Eos
Camera: Panasonic DMC-GX7 | Date: 30-01-2015 17:00 | Resolution: 4894 x 3059 | ISO: 320 | Exp. bias: -66/100 EV | Exp. Time: 1/60s | Aperture: 5.0 | Focal Length: 17.0mm | Lens: LUMIX G VARIO PZ 14-42/F3.5-5.6

My programming project of the last few weeks has been to build my own “rolling portfolio”, which shows random images from my photographic portfolio as either a screensaver or a rolling display on a second monitor. I’ve implemented a number of features I’ve always wanted but never had from freeware/shareware options, like precise control over timing, the ability to quickly add a note if I see a required correction, and the ability to locate and review recent images if someone says “what was that picture you were just showing?”.

Having previous blogged about the poor quality of “random” algorithms in Android music player apps (see  How Hard Can It Possibly Be?), I decided to put my money where my mouth is, and write my own preferred random algorithm. This does a recursive, random walk down the selected folder tree, until it either finds an image file, or a dead end (and then tries again). This was refreshingly easy to implement, and as expected runs quickly without needing any prior indexing of the content.

Also as expected, the simplest implementation returned a disproportionate number of hits (and therefore a lot of repeats) from folders with a very small number of images, but that was easily fixed by adding a “weighting” at the second stage of the walk, to reduce the number of hits on smaller portfolios.

Job done? Maybe. I started to notice that I still see the same image selected twice in quick succession, and sometimes more than twice over a day or two. At first I thought this might be an issue with seeding the random number generator, so that I was re-generating the same random sequences, but a quick check confirmed that wasn’t the problem. The next most obvious possibility (to me!) was an issue with the Microsoft .Net random() function, so I added some logging to the app, recording each random number, and then fed a day’s worth through some frequency analysis in Excel. That got Microsoft off the hook with a clean bill of health: there’s a slight preponderance of zeros, which I can explain, but otherwise the spread of results looks fine.

At the same time, I also added logging for the selected images themselves. In yesterday’s work hours operation the screen saver showed 335 images, of which no fewer than 21 were duplicates. Given that I have over 3500 images in the portfolio, this seems very high, but maybe not.

This is a known problem in mathematics, a generalisation of the “birthday problem”. It’s so known, because a common formulation is the question “given a room of people, what is the probability that at least two have the same birthday?”. While you need at 367 people to guarantee a duplicate, the counter-intuitive result is that with just 23 people in the room, it’s more likely than not. The generalised equation for the solution is the following:

E = k – n + n(1 – 1/n)k

In this n is the number of items, k is the number of random selections, and E is the expected number of duplicates. Feed in k = 335 and n = 3500, and you get the outcome E = 16. That’s close enough to my observed value of 21 (this is all random, so any one measurement might be either side of the expected value, but the order of magnitude is right). Couple this with the way my mind works, looking for patterns, and I must therefore expect to see some repetition. However it’s clear that the algorithm is working fine, it’s just the normal workings of probability.

Another implication of this is that as the sample grows, some images will naturally appear several times, and others may not appear at all. If we take 3500 samples, the expected number of duplicates rises to over 1200, so over 1/3 of the images will still be unselected.

Do I fix this? The relatively simple resolution is to keep a list of selected images, and use that to discard any selections which are repeats during a given period. However I would rather run this without a data store and maybe, now I can explain it, I’m comfortable. Time will tell.

View featured image in Album
Posted in Code & Development, Photography, Thoughts on the World | Leave a comment

The Jester and The Unicorn

A fable, sort of… The jester who wanted to be king asked the crowd “Do you want a purple unicorn?” Almost half the crowd said “We are happy as we are, and we don’t believe unicorns exist”, but slightly more Continue reading

Wednesday, March 13, 2019 in Humour, Thoughts on the World

Icons, or Heroes?

I’m slowly working through, and very much enjoying the BBC series Icons. There’s been a lot of discussion about whether it makes any sense to have a "final" in which "iconic" sportsmen, politicians and scientists go head to head, but Continue reading

Friday, February 15, 2019 in Thoughts on the World

The Favourite: A Great Opportunity Missed

I was really looking forward to The Favourite. It had a lot going for it. The period – the reign of Queen Anne, the end of the Stuart dynasty and the wars with Louis XIV – is an important piece Continue reading

Wednesday, January 2, 2019 in Thoughts on the World

Why I Like My MacBook, But I’m Beginning To Really Hate Apple

Battery Replacement on a 2015 MacBook I realised a couple of weeks ago, much to my horror and chagrin, that I had been walking around with a potential incendiary bomb. Not that I had done anything wrong – this is Continue reading

Monday, December 17, 2018 in PCs/Laptops, Thoughts on the World

Normal Service Will Be Resumed After Completion Of This Rant

The last day of any trip is always a bit sad, and hard work with the travel. However this year three separate organisations covered themselves in something which is not glory, and I have to get this out of my Continue reading

Wednesday, December 5, 2018 in Humour, Namibia Travel Blog, Thoughts on the World, Travel

The British Government Reviews Its Brexit Strategy

Sorry it’s a bit fuzzy and not properly focused, but that’s nothing to do with my photography! Continue reading

Sunday, November 25, 2018 in Humour, Myanmar Travel Blog, Thoughts on the World, Travel

Fraud Prevention: Why Don’t Banks Do More?

Banks constantly tell us to do more to protect our financial details against online fraud, but we live in a world where there is often no alternative to exposing important financial information to potential misuse. The frustration is that there Continue reading

Thursday, August 30, 2018 in Thoughts on the World

Is Theatre Killing Theatre?

Is the theatre its own worst enemy? Is it the engine of its own destruction? Let me explain what I mean. We love the cinema. We go most weeks, and most weeks we come away feeling well entertained, even inspired. Continue reading

Tuesday, August 28, 2018 in Thoughts on the World

That Was Too easy…

There is an old plot device, which goes back to at least Homer, although the version which popped into my head this evening was Genesis of the Daleks, a 1970s Dr Who story. A group of warriors fight a short Continue reading

Thursday, July 26, 2018 in Android, Thoughts on the World

Prediction Realised: The AlpinerX

In October last year I wrote an article celebrating the hybrid analogue/digital watch and offering some architecture and design observations from my collection of them. I ended up slightly sad about the style’s fall from fashion, but confidently predicting that Continue reading

Friday, July 6, 2018 in Thoughts on the World, Watches

Panasonic G9. Close? Yes. Cigar? No.

This article was also published as a guest article on "The Online Photographer". My Panasonic GX8 arrived pretty much on the day of official availability and has been my primary camera for almost three years, including two major photographic trips, Continue reading

Friday, June 8, 2018 in Micro Four Thirds, Photography, Thoughts on the World