Generating Random Sequences (part I)

September 29, 2009

Every once in a while, we need a random sequence. Whether to test a data structure’s performance or to run probabilistic unit tests, the provided rand primitive from your favorite programming language has several limitations. First, it’s been known for a while that if most implementations of the C standard library rand() function are not very random, despite being “good enough” in great many cases. Second, and more importantly, it does not allow you to easily control the period nor to generate a permutation on 0\ldots n-1, for example.

dice

There are many methods of generating pseudo-random number sequences. Not all exhibit the same properties and, accordingly, a method may be more useful in one case and perfectly useless in another. High quality pseudo-random number generation is a notoriously hard endeavor, but there is a number of very simple algorithms that will get you out of trouble for certain specific tasks. Let us consider, for example, the example where the pseudo-random generator must generate the numbers in 0\ldots{}n-1 exactly once, in a random order, of course, in exactly n draws.

Read the rest of this entry »


The Zune Freezes: More on Unit Testing

September 22, 2009

Do you remember the epic fail that bricked the Zune a whole day on the last day of last year, a bisextile year? I described here and here how this error could have been entirely avoided using basic unit testing.

brick-small

You probably remember (if you read the original post) that I first claimed that it’d take a few seconds to check all possible dates but in fact it ended up taking something like 90 minutes. This week, I come back on unit testing of a very large domain under a time constraint.

Read the rest of this entry »


A quick Bash Fix

September 16, 2009

Remember, not too long ago I told you how to shorten path names in a Bash prompt? Well two things. Apparently, there’s a similar mechanism in Bash 4.0 with PROMPT_DIRTRIM(which I haven’t tried yet). Second, noticed that I’m frequently using many terminals opened on many machines, and I’m not always sure which is which. Using uname -n in the terminal spews the machine name, but it’d be much better if the name appeared in the terminal title bar. To do so, use the same prompt I used previously, and add $HOSTNAME (a Bash variable that holds the machine’s name) in there:

PS1='\[\033]0;$HOSTNAME: $(shorten_path "${PWD}" 50)\007\]$(shorten_path "${PWD}" 50) >'

(again, use the view plain mode if WordPress messes up the syntax again)


What’s a Good Color Scheme?

September 15, 2009

Although EMACS is growing old, filled with passé idiosyncrasies, and rather complicated to tweak, I grew accustomed to it and is now my main editor. I use it for shell scripting, C++, HTML, even. But to use EMACS properly, or a least make it enjoyable a little bit, one must do a fair bit of configuration. Key bindings to match modern keyboards, adding the macros you’re using the most, and, finally, adjusting the color scheme so that your eyes do not bleed after a few hours of work.

yeux-saignants

But what is a good color scheme?

Read the rest of this entry »


Suggested Reading: La Nouvelle Grammaire en Tableaux

September 11, 2009

Marie-Éva de Villiers — La Nouvelle Grammaire en Tableaux et Recueil de Conjugaison — Québec Amérique, 2009, 324 pp. ISBN 978-2-7644-0690-8

(<del>Buy at Amazon.com</del>)

(Buy at Amazon.com)

Normally, I suggest English books, but since I know a certain part of my lectorate is French-speaking, I will make, now and then, an exception.

Un ouvrage de référence indispensable s’il en est un. Ce guide de la grammaire Française en plus d’être le plus à jour, a la particularité d’être très clair et complet; comme son titre le laisse entendre, l’information est présentée par tableaux, du genre if-then-else, chacun d’une grande simplicité mais aussi très complet. Pour comprendre l’usage du subjonctif plus-que-parfait (dont l’usage rare se fait trop souvent le prétexte aux phrases phonétiquement ambiguës — et aux farces salées) il suffit de consulter le tableau « concordance des temps dans la phrase. » Des néologismes ? Aucun problème ! Consultez le guide d’usage et de formation des néologismes.

Une lecture obligatoire pour tout bloggueur, thésard ou communicateur!

(hit Google Translate for fun)


Can you survive your Data Hiroshima?

September 8, 2009

Even expensive and top-of-the-line hardware is fallible. Last night (at the time of writing) my main workstation’s PSU burned. I mean, not soft-failed and powered down, I mean burned. With the acrid smell filling the room, I knew something went very wrong the instant I entered my study. I found my computer powered down, non-responsive. I wasn’t too worried because I knew that even if the computer went dead for good, I would not loose much data since, you know, I have backups.

nuclear-test-(unknown)

Are you capable of surviving your own little Data Hiroshima?

Read the rest of this entry »


Suggested Reading:The LATEX Companion

September 4, 2009

Frank Mittelbach, Michel Goossens, Johannes Braams, David Carlisle, Chris Rowley — The LATEX Companion — 2nd ed, Addison Wesley, 2006, 1090 pp. ISBN 0-201-36299-6

(Buy at Amazon.com)

(Buy at Amazon)

I should have told you about this book a long time ago. The LaTeX Companion is the definitive guide to LaTeX, ideal for anyone using it on a daily basis (or almost, as I do) or anyone wanting to learn LaTex. LaTeX is a complex and sophisticated mark-up language aimed at producing better typography for mathematics and scientific work—in which it totally succeeds. As for Linux, LaTeX (and TeX) comes in many distributions, some more geared toward the humanities, other for science, and still other for exquisite “art” typesetting.

A must read for graduate students.

*
* *

On the web: