Working product with sustainable legacies

This commit is contained in:
2025-10-18 20:44:30 +02:00
parent 65a1c9f159
commit a392132fa9
8 changed files with 178 additions and 54 deletions

15
chart.c
View File

@@ -6,11 +6,14 @@
#include <stdlib.h>
#include <string.h>
#include "chart.h"
#include "util.h"
struct chart new_chart(unsigned int length)
struct chart
new_chart(unsigned int length)
{
unsigned int i;
double price;
@@ -25,8 +28,16 @@ struct chart new_chart(unsigned int length)
for (i = 0; i < length; i++) {
chart.prices[i] = price;
price += (double)rand() / RAND_MAX - 0.4;
price += (double)rand() / RAND_MAX * 4 - 2;
}
return chart;
}
void
update_chart(struct chart *chart)
{
memmove(chart->prices, chart->prices + 1, (chart->length - 1) * sizeof(double));
chart->prices[chart->length - 1] = chart->prices[chart->length - 2] + (double)rand() / RAND_MAX * 4 - 2;
}