O Ruby Where Art Thou?

Posted by

I love Ruby. I have a feeling this is a theme I will visit again from time to time. I don’t mean to downplay the importance of C, but I hate coding in it.

I took a class on parallel computing and the culminating project in that class is to implement the solution to an NP-complete problem sequentially and using OpenMP and using OpenMPI, which are libraries for parallelizing code. Turns out those libraries work with your choice of Fortran, C, or C++. So I’m stuck with C.

To compound my problems I enjoy extending these kinds of projects. I have an interest in genetic algorithms, so rather than just brute force the Traveling Salesman Problem, I thought it would be infinitely cooler to parallelize the genetic algorithm for solving the Traveling Salesman Problem!

Anyways to make a long story short, I have spent my morning trying to generate random numbers and pass a two-dimensional array to a function in C. Things I’ve done about a hundred times in Ruby–with ease.

int random_in_range (unsigned int min, unsigned int max) {
int base_random = rand(); /* in [0, RAND_MAX] */

if (RAND_MAX == base_random) return random_in_range(min, max);
/* now guaranteed to be in [0, RAND_MAX) */
int range = max – min;
int remainder = RAND_MAX % range;
int bucket = RAND_MAX / range;
/* There are range buckets, plus one smaller interval
within remainder of RAND_MAX */
if (base_random < RAND_MAX - remainder) {
return min + base_random/bucket;
else {
return random_in_range (min, max);

At this point, I feel like I have done a good deal of programming in a wide array of languages and tools.  And without fail, every time I’m not working with Ruby I find myself thinking, “This would have been so much easier in Ruby.”

Add a comment

ds106 in[SPIRE]