Working product with sustainable legacies
This commit is contained in:
15
chart.c
15
chart.c
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user