Add markov chain implementation
This commit is contained in:
parent
3f6facf64e
commit
0100fff828
21
src/chain.c
Normal file
21
src/chain.c
Normal 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
39
src/chain.h
Normal 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_
|
16
src/main.c
16
src/main.c
@ -6,6 +6,18 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv){
|
||||
printf("Hello World!\n");
|
||||
#include "chain.h"
|
||||
|
||||
#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){
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user