Tuesday, March 31, 2009

First!

I probably should have started a blog long ago. I've oft wanted to rant about random stuff, and I tended to dump my ideas into IRC and forums. Now that I have some necessity for a blog, a better understanding of what a blog is, and have noticed that many of my Google searches for help land me on blogs, I too have a blog that I hope will be useful to many.

I will probably talk mostly about programming (mainly C) and Linux, though other topics may come to mind. I will never ever cuss on this blog, nor do I plan to say anything worse than "crap" or "drugs". Feel free to let your mother, grandmother, kids, and teacher/boss who's standing right behind you read this blog (if they're interested).

To round up this post and to round up some hits, here's a simple routine in C for randomly scrambling an array:
void scramble(void *base, size_t nmemb, size_t size) {
char *i = base;
char *o;
size_t sd;
for (;nmemb>1;nmemb--) {
o = i + size*(random()%nmemb);
for (sd=size;sd--;) {
char tmp = *o;
*o++ = *i;
*i++ = tmp;
}
}
}
Note that it has horrendous cache performance for large arrays.

No comments:

Post a Comment