Friday, 20 September 2019

Why songs repeat on your phone when played on shuffle?

When you have your favourite radio station playing songs that are not so favourite of yours the greatest thrill is to finally hear the intro of the one that you’ve been waiting for… for last three hours.

Well, those days are gone into the abyss of the past. We can have hundreds upon hundreds of our favourite songs right in our palm, literally. Our mobile phones have enormous capacities nowadays and it is easy to collect overwhelmingly large numbers of songs.

Many of these tunes are mildly amusing to us but we still keep them just because we can or we liked them initially, paid for them and now they’ve gotten old and we have moved on, yet we keep them for old time’s sake. Many a times, we just want to possess them but not really play them. But when you have over 500 tracks in your phone and you’re playing them on shuffle, somehow same songs keep repeating and the ones that you’re really waiting for never seem to play, just like old times when all you had was your trusty old radio.

I have suffered from the same first-world problem for a while now. I have recently bought and downloaded about half a dozen new tracks and dutifully included them in my 800 plus tracks long playlist. However, my phone seems to hate these tracks. They have yet to come on. I have played over 600 songs including all the repeats.

One afternoon, I had some time to kill and Microsoft Office handy. I decided to do some research as to why some songs play more often than others.

First of all, you must understand that the shuffle feature uses a randomization function included in every programming language that I have come across. It has different names in different programming languages but has the same purpose – to generate a random fraction between 0.000 and 0.999 inclusively. Once a random fraction has been generated any number can be returned by using simple arithmetic. This randomization can be used for electronic toss, generate lottery results or pick items from a list randomly. Our phones use the same randomization to randomly pick songs to play for us. However, turns out there is a caveat.

Randomization is not hundred percent random in a manner of speaking. Some numbers come up more often than others. Why? I don’t know. I did not dig that deep. What I did was run a hypothetical scenario with the help of randomization feature in Microsoft Excel and then analyzed it with Microsoft Access.

I created a list of integers, 1 to 850, each number representing a unique song in my phone. Then I asked Excel to randomly pick a number 850 times out of these 850 numbers. I repeated the process 5 times. In this hypothetical scenario, I have 850 songs. My phone played 4,250 songs – each song is counted each time it’s played, for example if Gangnam Style is played 5 times it’s counted as 5 songs. I wanted to see after 4,250 playbacks, going through 850 playbacks (total number of my songs) 5 times over, which songs were repeated and which ones were skipped altogether by the randomization system employed by the shuffle feature of music player application.
I gathered all the numbers and analyzed them. The result was surprising, if not shocking. In 4,250 hypothetical playbacks, 3 songs were never played and 29 songs were played 10 or more times. 161 songs were played 5 times. More than 96% of songs were repeated more than once.

37% of the songs were repeated more than 5 times when in 5 cycles of 850 playbacks, ideally no song should be repeated more than 5 times.

Interestingly, 30 songs were played only once and 44% songs were played less than 5 times.

This analysis reveals that using a simple randomization for shuffling songs in a playlist leaves much to be desired. Ideally, before the beginning of first song in any given playlist, the songs should be shuffled in a way that none repeat until all on them have been played at least once. It is not too difficult and might take a few milliseconds more than just randomly picking tracks from the list.

Sunday, 16 October 2016

The Muslim Burden

These days, if you look under any online article with any reference to Islam – direct or indirect – you will notice that the comment section is full of unbelievable hate, bigotry and xenophobic name calling against Muslims, provided that the host carrying that article allows comments in the first place. Based on writing style, references and demands made of governments, society in general and Muslims, you can easily deduce that almost all these posters of anti-Muslim vitriol are whites for whom white is the new black.

The targets of this hate are varied and singular at the same time. the common element in these hateful literary gems is Islam and their targets are Muslims in general, Muslim women, Muslim men, Muslims who immigrate to west, Muslims who never immigrated, Islam, Allah, Makkah, Medina, Arab Culture, attires associated to Muslims, Muhammad, Muhammad’s married life and last but not least Quran.

Here are some summaries of how hatred is thrown at some elements related to Islam and my responses:

Hateful Claim 1:

Muslims are always violent and every Muslim is out to kill non-Muslims.

My Response 1:

When was the last time you were killed by a Muslim just because you were not a Muslim?

Almost all highly publicised terrorist activities that are done in the name of Islam are perpetrated by the people who are influenced by Salafi school of thought or Salafism. It is a rather extremist branch or sub-sect of Sunnism, which itself is a major and extremely diverse sect of Islam. Many Arab states, including America’s overt and Israel’s covert ally Saudi Arabia, are politically dominated by Salafism. These states secretly facilitated the rise of ISIS or ISIL in Syria and Iraq. Before that, they heavily funded Arab and Afghan Mujahedeen in Soviet-Afghan war. After the end of the conflict and demise of Soviet Union, these Mujahedeen became unemployed and turned towards infighting and terrorism out of which Taliban and Al-Qaeda were born.

The problem is that the money talks. Salafis in Middle East have tons of it and they are still pumping it to spread their own extremist worldview. I do not know if they anticipated ISIS to get this out of control as it is threatening the same Arab countries that helped establish it, however, the fact remains that Arab money is not just talking. It is shouting its hatred in all venues available and accessible to the vulnerable young generations of Muslims. In today’s anti-religion society, most young Muslims have no idea what Islam is. Many, as a result, are exposed to Salafi propaganda machine which presents itself one and only real Islam and appeals to the thrill seekers amongst them. For many such young people, violence is extremely attractive way of getting noticed. A young Muslim kills a bunch of innocent people out in a street and gets killed alongside for the same reason as a young white man enters a schools and murders innocent students in cold blood and in the end gets shot, mostly by his own hand. In both instances, perpetrators might proclaim two very distinct reasons, however, the fundamental reason and motivation for such horrific acts are the same; untapped energy and lack of direction and narcissism.

Hateful Claim 2:

Muslim women cover their bodies because they are oppressed by men or they have been brainwashed.

My Response 2:

Western women like to exhibit their half or even fully naked bodies because they are oppressed by mass media run by men or they have been brainwashed into believing that they aren’t beautiful unless they show-off their goods in public or on warm beaches. Well that was a cheap shot. I apologise.

For many Muslim women, covering up in public is as normal as bikini on a beach for western women. Many highly educated strong Muslim women, who are extremely independent in their life choices, are choosing to follow the dress code known as Hijab as a personal choice. For them, it is not just a question of what their religion requires of them but also it is a principle of independence and personal identity. If you force a woman into what she might consider nudity, it would not only be misogynistic but also assault on her life, liberty and happiness. In your hate, do not forget that not all independent women are asking for freedom to go topless in public, some are asking for freedom to be covered-up and freedom to not put their most intimate parts on display in tight, minimal or no clothing at all.

Hateful Claim 3:

Arabs wear robes, which is somehow a bad thing, and they are towelheads.

My Response 3:

Not all Muslims are Arabs. In fact, only roughly 13% of Muslims are Arabs. However, I feel that it would be a disservice to my Arab ancestors if I didn’t explain the Arab attire to my fellow human beings with less skin pigmentation.

Just like in winters of Europe and North America when the temperatures dip below 0°C (32°F) bundling up doesn’t remain optional but a necessity, lack of which could have deadly results, in the summers of Middle East when temperatures soar above 40°C (104°F) baring it all to beat the heat does not remain an option and such an attempt quickly turns into a misadventure – even stupidity, if you will, and a deadly one at that. Arab clothing and headgear is the result of warmer climate and very hot summers of Middle East.

Before the advent of modern technology, Arabs had to work and travel in temperatures that were well above 40°C (104°F) on regular basis. In vast deserts of Middle East, it is not uncommon to find no sign of vegetation or trees, hence no respite from scorching sun, for hundreds of kilometers. In this kind of heat, if temperatures don’t kill you sunburn will. Arabs, over more than past two millennia, have developed their traditional garb not because of tradition or even religion but because of necessity and practicality. The Middle Eastern outfits are simple, practical and easy to maintain. They protect you from scorching sun and blowing sand and, at the same time, let breeze in and provide enough ventilation to help a human body keep a bearable, if not comfortable, temperature. In North America, many people, from various backgrounds, who work outside in summer, on really hot days often put a towel, handkerchief or some other piece of cloth under their baseball cap or hard hat to cover the backsides of their heads and necks from sun. Does this way of protection from heat remind you of something? It serves the same purpose as traditional headgear, called keffiyeh, worn by Arabs.

In conclusion, traditional clothing of Arabs was born out of practicality rather than religion and if someone from Middle East insists on wearing it in cold winters of North America it is not because of religious obligation but out of sheer pride on traditions and also because modern indoor climate control technology lets them do so. Some North American Muslims of mostly Indian background tend to wear Arab clothing with a belief that this garb is somehow Islamic, which is another sign of religious ignorance of modern Muslims.

Hateful Claim 4:

Muslims do not condemn terrorism and even tacitly support it.

My Response 4:

Imagine a scenario. Forget about scenario. Remember all those attacks on Americans on foreign soils where many US citizens were killed and injured and the attackers claimed that the attacks were in retaliation to US foreign policy? Since the end of Second World War, US has always been involved in one armed conflict or another with its boots on the ground on foreign soils. All those soldiers, while serving their country, end up dying for dubious reasons which are often extracted from the whimsical ideologies and beliefs of some hawkish politicians who managed to get elected with empty promises of better lives for average Americans.

How would an average American feel if someone came up to them and asked them to condemn and apologise for the actions of their government? An average American has nothing to do with the actions of US government and the reactions to those actions. No one is justified in asking any average American, who is not on a powerful position in government, to condemn unjust violence brought upon peoples of other countries by successive US governments.

All of the terrorism committed in the name of Islam is result of actions of different governments or reactions to those actions. US government is always one of those bungling administrations.

Just because US governments are killing people in the name of US, why should an average American be asked to vocally condemn such atrocities?

Just because terrorists are killing people in the name of Islam, why should an average Muslim be asked to vocally condemn such atrocities?

Hateful Claim 5:

Muhammad was a pedophile because he married a 6-years-old.

My Response 5:

First of all, the concept of pedophilia is very new and modern, and is not applicable to something that took place more than 1400 hundred years ago. People, in their raging hatred of Muslims, forget that marriage at much younger ages, especially for women, was common throughout the entire world. Even today, in many US states, even though a woman is considered officially adult at the age of 18, she can get married at the age of 16 with parental consent – a legal paradox which will make her husband technically a pedophile.

The most commonly cited source about the age of Ayesha, the supposed child-bride of Muhammad, is herself. Her claim that she was 9 at the time of consummation of her marriage cannot be historically verified. Some historians have refuted the claims about her being so young at the time of her marriage and have put her age between 16 and 19 at the minimum.

One explanation for Ayesha’s age is that like many Arabs of her time, Ayesha had a habit of using short forms of words in her conversation. This practice of diminution of words was not let down even for the numbers. Therefore, 16 became 6 and 19 became 9. This practice can be seen in North America during the conversations about motor vehicles and residential units. Price of a car can be 37 (meaning $37,000) or 14 (meaning $14,000). A new condo could cost you in low 200’s (meaning above $200,000 and below $250,000).

Muslim clerics, throughout varied cultures where Islam eventually became primary religion, have been promoting Ayesha’s supposed young age as a way of allowing for child marriages and to provide a religious cover to a cultural practice which eventually became first a transgression in the eyes of the society then a crime in the eyes of the law.

Conclusion:

Muslims don’t believe in Jesus’ crucifixion, however, he, being a prophet of Islam, provides them a guiding beacon with his patience and resilience against all the opposition and oppression which he endured. Those terrorists, who claim to be Muslims and followers of Muhammad and yet kill innocent non-combatant non-Muslims in the name of Islam, have forgotten that Muhammad’s charity didn’t ask the religion when he gave up his only meal in several days to feed a hungry, when his shoes were full of blood and he refused to wish ill of those people who made him bleed, when he tended to a sick old woman who used to throw garbage at him from her roof as he walked past her house.

Muhammad’s charity, Jesus’ suffering, Job’s patience, Abraham’s sacrifice, Moses’ strength, each and every one of these historical figures is a guiding beacon of Islam. All these prophets were sent by the same God to many different people to guide them to the same path of piety and care for fellow human beings. Some modern Muslims, in their quest for an Islamic Utopia, which never existed and they falsely believe that it did right after the time of Prophet Muhammad, have gone overboard and have brought destruction upon all those that they deem obstacles – including other Muslims – leaving a trail of dystopian carnage behind them. These so-called Islamists will never be able to realize the utopia that they seek for nothing of this sort is possible, and also because those who seemingly peruse a dream of caliphate are in this struggle not to achieve a goal but the violence that is supposed to achieve that goal. It’s not the destination but the journey that matters.

The ordinary Muslims, who have nothing to do with terrorism, who don’t even understand the reasons behind terrorists attacks and are even victims of majority of terrorism, should not be expected to apologise for things that did not do. However, an ordinary Muslim who is working hard to provide for his or her family is expected to constantly show remorse and be contrite for things he or she has nothing to do with. That’s the Muslim burden. A clown wears ridiculous makeup to show that he is funny, regardless of whether or not he is able to get any laughs. Sometimes it feels like ordinary Muslims are expected to constantly wear some kind of apology makeup to show others how embarrassed and sorry they are for the actions of what some other people did in the name of Islam. This burden is getting too much to bear.

Sunday, 19 June 2016

Microsoft Excel: Calculating Aspect Ratios

You have downloaded a video file from internet (hopefully legally) and when you play it, something just doesn’t feel right; the picture looks squished (basketball athletes look short) or stretched (supermodels look plus-sized models). You want to know the video’s aspect ratio and compare to what it should be from the looks of it. Most players will readily tell you the resolution of a video but finding its aspect ratio can be tricky if not impossible. Sometimes the information given is just not reliable.

You can reliably calculate any video’s aspect ratio – provided that you already know its resolution – by using following formula in Microsoft Excel:

=A2/GCD($A$2,$B$2)

Or

=A2/GCD($A$2:$B$2)

The only difference between these two formulas is that the first one uses references to individual cells as indicated by comma and the second one uses a range of cells as indicated by the colon character. In each case, refernces include only two cells, A2 and B2. A2 contains width of the video and B2 contains its height.

How to Use

Let us say you have a small video with a resolution of 320x240 which means its height is 320 pixels and height is 240 pixels. You want to calculate aspect ration of this video. First look at following screen capture:


Start a new work sheet. Just like in the picture above, type 320 in A2 and 240 in B2.

In A3, type =A2/GCD($A$2,$B$2) and press Enter. Click on A3, copy this cell in B3. In formula bar, the formula will look like =B2/GCD($A$2,$B$2). If you notice only one reference was updated in the formula, that is B2. It is because $ sign in a reference makes it absolute and tells Excel not to change it when the formula containing it is copied.

In above example, aspect ratio of your video is 4:3 or 1.33:1 if you divide both numbers by 3.

Here is another example:


Try doing it yourself and use =A2/GCD($A$2:$B$2) for this example. Here, too, the aspect ratio is 4:3.

Non-standard Aspect Ratio

Poorly processed videos, and most pictures and photographs available online have non-standard aspect ratios like in following example:


As per above calculation a video or a picture with resolution of 854x480 has an aspect ratio of 427:240 or 1.78:1 if you divide both numbers by 240.

Desktop Wallpapers

Sometimes you download or take a really nice picture and you want to use it as your desktop wallpaper. You know that your operating system will stretch or shrink the image to fit it on your desktop, however, if the aspect ratio of the picture is not same as your monitor, it will look squished or stretched. To find out beforehand if the photograph that you want to use is appropriate for your monitor you can use same techniques in Excel described above. Let us look at an example:



In this hypothetical scenario, we have photograph with resolution 5312x2988. Such resolutions are common in modern digital photography. In this example, the computer user still has an old CRT monitor with 1024x768 resolution. Using above formulas, the user finds out that the picture has modern wide-screen aspect ratio of 16:9 and his monitor is 4:3, which means he must crop the photograph to make it look decent on his desktop. In other words, before using a picture as a wallpaper for your desktop, make sure that its aspect ratio is exactly the same as your monitor. Pictures of equal and larger resolution than that of your monitor make better wallpapers with crisper edges and tones, however, if their aspect ratios do not match your monitor the results can be a bit unsightly.

Simpler Calculation: Ratios with Decimals

There is a much simpler way of calculating aspect ratios which can be done with any hand-held electronic calculator as well as Microsoft Excel. Let us take two resolutions from last example above. In each of 5312x2988 and 1024x768 divide each number on both sides of x with smaller of the two. For example, in 5312x2988 divide both 5312 and 2988 by 2988 – smaller of the two – to get 1.78:1. You can get same result by dividing both sides of 16:9 by 9. Similarly, with 1024x768 and 4:3, you get 1.33:1.

Despite these ratios with decimals are easier to calculate and more readily referred to in many technical literatures, they are not easily understood by most people as decimal numbers are not strong suite for them, or these numbers are not as straight-forward as ratios involving integers only. Personally, I prefer non-decimal (integer) ratios over decimal ratios.

Tuesday, 24 November 2015

Canada Post FlexDelivery: Review Appendant

This is second installment of (or shall we say a supplementary to) my earlier blog about Canada Post’s FlexDelivery feature.

After experimenting with some packages, delivered to my local post office, from different sellers I have come to the conclusion that unless a package is trackable with a tracking number, FlexDelivery system will not email you to notify that your package is ready for pick up at the post office.

Someone has mentioned in one of the comments under my previous blog on this topic that the packages ordered from abroad are not being notified about via email when they are at the chosen post office. In my experience, most sellers who send packages overseas – across the border in case of most of the US – they use the cheapest modes of shipping, which, in most cases, do not offer a tracking number; even if they do it is useful only within the country of origin of the shipment. The barcodes from other countries are not scanned by Canada Post.

My guess would be that if an overseas seller uses an expensive or more reliable shipping method, there is a good chance that FlexDelivery will notify the buyer about the arrival of his or her packages.

In my observation, when a good (read expensive) shipping method is used by a seller abroad, the parcels sent so, once they enter Canada, are given Canada Post’s own tracking number barcodes which will be scanned, unlike those issued outside Canada, at the time of delivery to the post office of buyer’s choice.

To put it simply, if your package is trackable in Canada, FlexDelivery will notify you by email about its arrival at your PO Box address. Otherwise you are liable to potentially lose your long awaited parcel if you do not obsessively keep checking with your post office either in person or by phone.

Sunday, 28 June 2015

Microsoft Excel: Cricket: Convert Balls into Overs

In cricket, converting balls to overs is equally difficult as overs to balls when there are fractions of overs involved. If a given number of balls is a multiple of 6 (each over has 6 balls) a simple division is enough. If not, then you have to take the remainder and convert it into fraction part of resulting overs. For example, converting 19 balls to overs gives 3.1. Divide 19 by 6, answer is 3 and remainder is 1, hence, 3.1 overs.

Unfortunately, Microsoft Excel cannot handle this hybrid system of base 10 and base 6 mathematics that is the specialty of arithmetic of Cricket overs. To convert balls into overs in Excel use following formula:

=TRUNC(J17/6,0)+MOD(J17,6)/10

J17 is the address of cell containing balls. Following illustrates an example of this formula in action:





In above example, each yellow highlighted cell contains aforementioned formula. Turquoise highlighted cell contains formula explained here. Runs were added using a formula detailed here.

Wednesday, 24 June 2015

Microsoft Excel: Cricket: Convert Overs into Balls

In cricket, any digit after decimal point of a number representing overs is not fraction of overs but the balls of next incomplete over; for example: 3.2 overs means 3 overs and 2 balls. Converting 3 overs into balls with or without Microsoft Excel is simple. All you have to do is multiply 3 by 6 which would be 18 balls. To convert 3.2 overs into balls, first you multiply 3 by 6 to get 18, then add 2 to get 20. This can be a little challenging in Microsoft Excel too. To make it simple, use following formula:

=INT(J2)*6+(J2-INT(J2))*10

J2 is the address of cell containing overs with or without fraction. Following illustrates an example of this formula in action:



In above example, each yellow highlighted cell contains aforementioned formula. Turquoise highlighted cell contains formula explained here. Runs were added using a formula detailed here.

Thursday, 18 June 2015

Microsoft Excel: Convert Centimeters and Meters to Feet and Inches

Microsoft Excel does not have a built-in function to convert any measurement of length into inches and feet with single and double quote. Therefore, I have following formula that can convert any length specified in centimeters into feet and inches of x' x" format:

=TRUNC(B3/2.54/12)&"' "&TRUNC(MOD(B3/2.54,12))&""""

B3 is the address of cell containing centimeters.

Practical example:


Similarly, to convert meters into feet and inches of x' x" format use following formula:

=TRUNC(B8*100/2.54/12)&"' "&TRUNC(MOD(B8*100/2.54,12))&""""

B8 is the address of cell containing meters.

Practical example:



Warning: There are two disadvantages of above two formulas. First, results (6' 1" & 5' 3") are in text format rather than numerical format, therefore, they cannot be used in further calculations. Second, for simplicity sake, fractions of inches are simply dropped, not rounded off, but dropped.

Following formulas will round off inches to the nearest integer:

cm to ft' in"

=TRUNC(B3/2.54/12)&"' "&ROUND(MOD(B3/2.54,12),0)&""""

m to ft' in"

=TRUNC(B8*100/2.54/12)&"' "&ROUND(MOD(B8*100/2.54,12),0)&""""