Posted by Mejf on Tue 13 May 11:14
report spam | download | new post
- #include <stdio.h>
- #include <stdlib.h>
- int main( int argn, char *argv[] ) {
- int matrix[256][256];
- int total[256];
- int first, next, last;
- int l, m;
- first = last = fgetc(stdin);
- for (l = 0; l < 256; l++) {
- total[l] = 0;
- for (m = 0; m < 256; m++)
- matrix[l][m] = 0;
- }
- while ((next = fgetc(stdin)) != EOF) {
- matrix[last][next]++;
- total[last]++;
- last = next;
- }
- srandom(time(NULL));
- last = first;
- putchar(first);
- for (l = 0; l < 10000; l++) {
- if (total[last] <= 0) {
- break;
- }
- int r = random()%total[last] + 1;
- next = 0;
- while (1) {
- r -= matrix[last][next];
- if (r <= 0)
- break;
- next++;
- }
- putchar(next);
- last = next;
- }
- putchar('\n');
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.