Add markov chain implementation

This commit is contained in:
Tyler Perkins 2021-09-29 20:48:21 -04:00
parent 3f6facf64e
commit 0100fff828
3 changed files with 74 additions and 2 deletions

21
src/chain.c Normal file
View File

@ -0,0 +1,21 @@
///////////////////////////////////////////////////////////////////////////////
// Tyler Perkins
// 9-29-21
// Markov chain implementation
//
#include "chain.h"
m_node* m_next(const m_node* rhs){
uint16_t total = 0;
int i = 0;
uint16_t v = rand() % (sizeof(uint16_t) * 8);
while(v > total){
total += rhs->_conns[i]._probability;
++i;
}
return rhs->_conns[i]._node;
}

39
src/chain.h Normal file
View File

@ -0,0 +1,39 @@
///////////////////////////////////////////////////////////////////////////////
// Tyler Perkins
// 9-29-21
// Markov chain def
//
#ifndef _MARKOV_H_
#define _MARKOV_H_
#include <stdlib.h>
#include <time.h>
#include <stdint.h>
enum chord {
one = 0x01,
two = 0x02,
three = 0x04,
four = 0x08,
five = 0x10,
six = 0x20,
seven = 0x40,
};
// probability out of the size of a short
struct m_conn {
uint16_t _probability;
struct m_conn* _node;
};
struct m_node {
enum chord _chord;
struct m_conn* _conns;
};
typedef struct m_node m_node;
// get next node, respecting probability
m_node* m_next(const m_node*);
#endif //!_MARKOV_H_

View File

@ -6,6 +6,18 @@
#include <stdio.h> #include <stdio.h>
int main(int argc, char** argv){ #include "chain.h"
printf("Hello World!\n");
#define NOTE_COUNT 7
// sample version of how to progress
m_node* init(){
m_node* nodes = (m_node*)malloc(sizeof(m_node) * NOTE_COUNT);
}
int main(int argc, char** argv){
} }