#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, right of= 1] {2};n"); printf("\node (3) [state, thick, below of= 1] {3};nn"); printf("%Verbindungenn"); printf("\path[thick,->]n"); for (i = 0; i < 4; i++) { j = 0; fprintf(stderr, "%in", z [i][0]); if (z [i][j] == i) printf ("(%i) edge [loop above] node {%i/%i} (%i)n", i, j, rand () % 4, z[i][j]); else printf ("(%i) edge node {%i/%i} (%i)n", i, 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=15, bend left,below] node {%i/%i} (%i)n", i, j, rand () % 4, z[i][j]); } printf(";n"); printf("\end{tikzpicture}n"); printf("\end{center}n"); printf("\end{document}n"); return 0; }