random numbers are now somehow random
This commit is contained in:
parent
2654733c27
commit
614cfef7f2
2 changed files with 10 additions and 4 deletions
11
matrix.c
11
matrix.c
|
|
@ -2,8 +2,10 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#define MAX_BYTES 100
|
||||
|
||||
static int RANDOMIZED = 0;
|
||||
// operational functions
|
||||
Matrix* matrix_create(int rows, int columns) {
|
||||
|
||||
|
|
@ -17,7 +19,7 @@ Matrix* matrix_create(int rows, int columns) {
|
|||
// allocate memory for the numbers (2D-Array)
|
||||
matrix->numbers = malloc(sizeof(double*) * rows);
|
||||
for (int i = 0; i < rows; i++) {
|
||||
matrix->numbers[i] = malloc(sizeof(double) * columns);
|
||||
matrix->numbers[i] = calloc(sizeof(double), columns);
|
||||
}
|
||||
|
||||
// return the pointer to the allocated memory
|
||||
|
|
@ -189,7 +191,8 @@ Matrix* apply(double (*function)(double), Matrix* matrix) {
|
|||
// apply the function to all values in the matrix
|
||||
for (int i = 0; i < matrix->rows; i++) {
|
||||
for (int j = 0; j < matrix->columns; j++) {
|
||||
matrix->numbers[i][j] = (*function)(matrix->numbers[i][j]);
|
||||
result_matrix->numbers[i][j] = (*function)(matrix->numbers[i][j]);
|
||||
int k = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -350,6 +353,10 @@ int matrix_argmax(Matrix* matrix) {
|
|||
|
||||
void matrix_randomize(Matrix* matrix, int n) {
|
||||
|
||||
if(!RANDOMIZED){
|
||||
srand(time(NULL));
|
||||
RANDOMIZED = 1;
|
||||
}
|
||||
//make a min and max
|
||||
double min = -1.0f / sqrt(n);
|
||||
double max = 1.0f / sqrt(n);
|
||||
|
|
|
|||
Reference in a new issue