#N canvas 104 114 1003 515 10;
#N canvas 0 0 450 300 enumerate 0;
#N canvas 473 338 450 300 count 0;
#X obj 131 154 f 0;
#X obj 163 154 + 1;
#X msg 178 122 0;
#X obj 131 183 outlet;
#X obj 131 59 inlet;
#X obj 131 96 b;
#X obj 178 58 inlet;
#X obj 178 98 b;
#X connect 0 0 1 0;
#X connect 0 0 3 0;
#X connect 1 0 0 1;
#X connect 2 0 0 1;
#X connect 4 0 5 0;
#X connect 5 0 0 0;
#X connect 6 0 7 0;
#X connect 7 0 2 0;
#X restore 233 170 pd count;
#X obj 152 128 t a b;
#X obj 152 196 list prepend;
#X obj 152 72 inlet;
#X obj 152 228 outlet;
#X obj 286 74 inlet;
#X connect 0 0 2 1;
#X connect 1 0 2 0;
#X connect 1 1 0 0;
#X connect 2 0 4 0;
#X connect 3 0 1 0;
#X connect 5 0 0 1;
#X restore 602 154 pd enumerate;
#X msg 602 119 0 1 0 0 \, 1 0 0 1 \, 0 1 1 0 \, 0 1 1 0;
#X msg 545 144 bang;
#X floatatom 535 216 5 0 0 0 - - -;
#X obj 602 90 t b b;
#X msg 602 68 bang;
#X obj 535 86 hradio 15 1 0 4 empty empty empty 0 -8 0 10 -262144 -1
-1 0;
#X floatatom 535 109 5 0 0 0 - - -;
#X obj 535 236 hradio 15 1 0 4 empty empty empty 0 -8 0 10 -262144
-1 -1 0;
#X text 9 10 c_markov - 1st order markov chain;
#X obj 535 184 c_markov 4;
#N canvas 0 0 944 702 2nd-order-chain 0;
#N canvas 0 0 450 300 enumerate 0;
#N canvas 473 338 450 300 count 0;
#X obj 131 154 f 0;
#X obj 163 154 + 1;
#X msg 178 122 0;
#X obj 131 183 outlet;
#X obj 131 59 inlet;
#X obj 131 96 b;
#X obj 178 58 inlet;
#X obj 178 98 b;
#X connect 0 0 1 0;
#X connect 0 0 3 0;
#X connect 1 0 0 1;
#X connect 2 0 0 1;
#X connect 4 0 5 0;
#X connect 5 0 0 0;
#X connect 6 0 7 0;
#X connect 7 0 2 0;
#X restore 233 170 pd count;
#X obj 152 128 t a b;
#X obj 152 196 list prepend;
#X obj 152 72 inlet;
#X obj 152 228 outlet;
#X obj 286 74 inlet;
#X connect 0 0 2 1;
#X connect 1 0 2 0;
#X connect 1 1 0 0;
#X connect 2 0 4 0;
#X connect 3 0 1 0;
#X connect 5 0 0 1;
#X restore 50 204 pd enumerate;
#X msg 131 177 reset counter;
#X floatatom 79 556 5 0 0 0 - - -;
#X obj 50 119 t b b;
#X msg 50 93 bang;
#X text 242 39 three 3-state matrixes;
#N canvas 0 0 450 300 enumerate 0;
#N canvas 473 338 450 300 count 0;
#X obj 131 154 f 0;
#X obj 163 154 + 1;
#X msg 178 122 0;
#X obj 131 183 outlet;
#X obj 131 59 inlet;
#X obj 131 96 b;
#X obj 178 58 inlet;
#X obj 178 98 b;
#X connect 0 0 1 0;
#X connect 0 0 3 0;
#X connect 1 0 0 1;
#X connect 2 0 0 1;
#X connect 4 0 5 0;
#X connect 5 0 0 0;
#X connect 6 0 7 0;
#X connect 7 0 2 0;
#X restore 233 170 pd count;
#X obj 152 128 t a b;
#X obj 152 196 list prepend;
#X obj 152 72 inlet;
#X obj 152 228 outlet;
#X obj 286 74 inlet;
#X connect 0 0 2 1;
#X connect 1 0 2 0;
#X connect 1 1 0 0;
#X connect 2 0 4 0;
#X connect 3 0 1 0;
#X connect 5 0 0 1;
#X restore 248 201 pd enumerate;
#X msg 329 174 reset counter;
#X obj 248 116 t b b;
#X msg 248 90 bang;
#N canvas 0 0 450 300 enumerate 0;
#N canvas 473 338 450 300 count 0;
#X obj 131 154 f 0;
#X obj 163 154 + 1;
#X msg 178 122 0;
#X obj 131 183 outlet;
#X obj 131 59 inlet;
#X obj 131 96 b;
#X obj 178 58 inlet;
#X obj 178 98 b;
#X connect 0 0 1 0;
#X connect 0 0 3 0;
#X connect 1 0 0 1;
#X connect 2 0 0 1;
#X connect 4 0 5 0;
#X connect 5 0 0 0;
#X connect 6 0 7 0;
#X connect 7 0 2 0;
#X restore 233 170 pd count;
#X obj 152 128 t a b;
#X obj 152 196 list prepend;
#X obj 152 72 inlet;
#X obj 152 228 outlet;
#X obj 286 74 inlet;
#X connect 0 0 2 1;
#X connect 1 0 2 0;
#X connect 1 1 0 0;
#X connect 2 0 4 0;
#X connect 3 0 1 0;
#X connect 5 0 0 1;
#X restore 455 200 pd enumerate;
#X msg 536 173 reset counter;
#X obj 455 115 t b b;
#X msg 455 89 bang;
#X obj 455 235 s \$0-probs-2;
#X obj 248 236 s \$0-probs-1;
#X obj 50 239 s \$0-probs-0;
#X obj 160 506 r \$0-probs-0;
#X floatatom 278 557 5 0 0 0 - - -;
#X obj 359 507 r \$0-probs-1;
#X floatatom 474 558 5 0 0 0 - - -;
#X obj 555 508 r \$0-probs-2;
#X obj 79 428 route 0 1 2;
#X obj 278 531 c_markov 3;
#X obj 278 638 s \$0-state;
#X obj 132 342 r \$0-state;
#X obj 79 406 list prepend;
#X floatatom 79 502 5 0 0 0 - - -;
#X floatatom 278 505 5 0 0 0 - - -;
#X floatatom 474 499 5 0 0 0 - - -;
#X obj 101 342 f;
#X obj 101 316 metro 300;
#X obj 101 294 tgl 15 0 empty empty empty 17 7 0 10 -4034 -1 -1 0 1
;
#X msg 176 379 bang;
#X msg 455 137 1 1 1 \, 1 1 1 \, 1 1 1;
#X obj 79 583 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X obj 291 584 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#X obj 474 583 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#X obj 79 530 c_markov 3;
#X obj 474 532 c_markov 3;
#X obj 101 366 t f f;
#X text 178 411 This prepends the previous element to the current.
;
#X msg 50 141 1 0 1 \, 0 1 1 \, 0 1 1;
#X msg 248 138 1 0 0 \, 0 0 1 \, 0 1 0;
#X text 35 15 2nd order markov chains.;
#X obj 248 60 loadbang;
#X connect 0 0 16 0;
#X connect 1 0 0 1;
#X connect 2 0 24 0;
#X connect 2 0 35 0;
#X connect 3 0 42 0;
#X connect 3 1 1 0;
#X connect 4 0 3 0;
#X connect 6 0 15 0;
#X connect 7 0 6 1;
#X connect 8 0 43 0;
#X connect 8 1 7 0;
#X connect 9 0 8 0;
#X connect 10 0 14 0;
#X connect 11 0 10 1;
#X connect 12 0 34 0;
#X connect 12 1 11 0;
#X connect 13 0 12 0;
#X connect 17 0 38 1;
#X connect 18 0 24 0;
#X connect 18 0 36 0;
#X connect 19 0 23 1;
#X connect 20 0 24 0;
#X connect 20 0 37 0;
#X connect 21 0 39 1;
#X connect 22 0 27 0;
#X connect 22 1 28 0;
#X connect 22 2 29 0;
#X connect 23 0 18 0;
#X connect 25 0 30 1;
#X connect 26 0 22 0;
#X connect 27 0 38 0;
#X connect 28 0 23 0;
#X connect 29 0 39 0;
#X connect 30 0 40 0;
#X connect 31 0 30 0;
#X connect 32 0 31 0;
#X connect 33 0 26 1;
#X connect 34 0 10 0;
#X connect 38 0 2 0;
#X connect 39 0 20 0;
#X connect 40 0 26 1;
#X connect 40 1 26 0;
#X connect 42 0 0 0;
#X connect 43 0 6 0;
#X connect 45 0 4 0;
#X connect 45 0 9 0;
#X connect 45 0 13 0;
#X restore 514 313 pd 2nd-order-chain;
#X text 505 273 You can use c_markov to build 2nnd order chains as
shown in this subpatch:;
#X text 482 342 Also see:;
#X obj 508 364 u_dumpfile;
#X text 588 364 is very handy to load markov chains from textfile.
;
#X text 510 391 Use its "numdump" dumping method.;
#N canvas 550 144 695 621 REFERENCE 0;
#X text 114 121 Name: c_markov;
#X text 114 148 Summary: 1st order markov chain;
#X text 115 178 Argument 0: number of states (required);
#X text 115 258 Inlet 1: set probabilities per state as <state number>
<list of probabilities>. Each message sets a row in the transition
matrix.;
#X text 115 205 Inlet 0: float to set the current state and output
the state \, bang to get next state \, and "set <num>" to just set
the current state without generating a new one.;
#X text 115 311 Outlet 0: random number from 0 ... numstates-1;
#X text 113 342 Description: Generate random numbers following first
order Markov chain rules.;
#X text 118 401 Tags: random \, markov chain \, state machine;
#X coords 0 -1 1 1 450 450 1 100 100;
#X restore 11 35 pd REFERENCE;
#X connect 0 0 10 1;
#X connect 1 0 0 0;
#X connect 2 0 10 0;
#X connect 3 0 8 0;
#X connect 4 0 1 0;
#X connect 4 1 0 1;
#X connect 5 0 4 0;
#X connect 6 0 7 0;
#X connect 7 0 10 0;
#X connect 10 0 3 0;
