#include <stdio.h> #include <stdlib.h> #include <time.h> #define EMPTY_Z -1 #define UNINIT_Z -2 int main (void) { time_t t; int i, j; int z [4][2]; int flag; srand ((unsigned)time (\&t)); for (i = 0; i < 4; i++) { z [i][0] = i; z [i][1] = i; } flag = 0; while (!flag) { for (i = 0; i < 4; i++) { for (j = i + 1; j < 4; j++) { if ((rand () % 32) > 16) { t = z [j][0]; z [j][0] = z[i][0]; z [i][0] = t; } } } for (i = 0; i < 4; i++) { for (j = i + 1; j < 4; j++) { if ((rand () % 16) < 8) { t = z [j][1]; z [j][1] = z[i][1]; z [i][1] = t; } } } flag = 1; for (i = 0; i < 4; i++) if ((z[i][0] == z[i][1]) \&\& (z[i][1] == i)) { flag = 0; } } printf("\documentclass{article}n"); printf("\usepackage[utf8]{inputenc}n"); printf("\usepackage{pgf, tikz}n"); printf("\usetikzlibrary{arrows , automata , positioning}n"); printf("\begin{document}nn"); printf("\begin{center}n"); printf("\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=2.5cm]n"); printf("%Knotenn"); printf("\node (0) [state, thick] {0};n"); printf("\node (1) [state, thick, right of= 0] {1};n"); printf("\node (2) [state, thick, above of= 1, right of=1] {2};n"); printf("\node (3) [state, thick, above of= 2, left of=0] {3};nn"); printf("%Verbindungenn"); printf("\path[thick,->]n"); char *leftright [] = {"left", "right"}; char *abovebelow [] = {"above", "below"}; for (i = 0; i < 4; i++) { j = 0; fprintf(stderr, "%in", z [i][0]); if (z [i][j] == i) printf ("(%i) edge [loop] node {%i/%i} (%i)n", i, j, rand () % 4, z[i][j]); else printf ("(%i) edge [bend angle=%i, bend %s,%s] node {%i/%i} (%i)n", i, (i+1)*10+z[j][j]*5, leftright [(i>z[i][j])\&\&(z[i][j] != 3)], abovebelow [(i<=z[i][j])\&\&(z[i][j] != 3)], j, rand () % 4, z[i][j]); j = 1; if (z [i][j] == i) printf ("(%i) edge [loop] node {%i/%i} (%i)n", i, j, rand () % 4, z[i][j]); else printf ("(%i) edge [bend angle=%i, bend %s,%s] node {%i/%i} (%i)n", i, (i+1)*25+z[j][j]*8, leftright [(i<=z[i][j]) \&\&(z[i][j] != 3)], abovebelow [(i>z[i][j])\&\&(z[i][j] != 3)], j, rand () % 4, z[i][j]); } printf(";n"); printf("\end{tikzpicture}n"); printf("\end{center}n"); printf("\end{document}n"); return 0; }