Created
June 13, 2010 21:09
-
-
Save godfat/437007 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// clang -emit-llvm -c -o shuffle.bc shuffle.c | |
// llvm-dis < shuffle.bc | less | |
// llc -march=c -o shuffle.cbe.c shuffle.bc | |
// clang -emit-llvm -c -o shuffle.cbe.bc shuffle.cbe.c | |
// llvm-dis < shuffle.cbe.bc | less | |
// llc -march=c -o shuffle.cbe.cbe.c shuffle.cbe.bc | |
// wdiff -w (set_color red) -x (set_color normal) -y (set_color green) -z (set_color normal) shuffle.cbe.c shuffle.cbe.cbe.c | less --raw | |
#include <stdio.h> | |
#include <stdlib.h> | |
void swap(char* lhs, char* rhs){ | |
char tmp = *lhs; *lhs = *rhs; *rhs = tmp; | |
} | |
void shuffle(char letters[], int length){ | |
for(int i=0; i<length; ++i) | |
swap(&letters[i], &letters[i + rand() % (length - i)]); | |
} | |
int main(){ | |
srand(time(0)); | |
char letters[] = "abcdefghijklmnopqrstuvwxyz"; | |
shuffle(letters, 26); | |
letters[10] = 0; | |
printf("%s\n", letters); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment