misc.c

来自「这个代码是policy iteration算法关于强化学习的. 请您用winzi」· C语言 代码 · 共 81 行

C
81
字号


#include <stdlib.h>
#include <stdio.h>
#include <time.h>

#include "misc.h"


void *My_Malloc(long size) 
{
	void *ptr;
	
	ptr=(void *)malloc(size);
	
	if(!ptr) 
	{ 
		My_Error("Out of memory!"); 
	}
	return(ptr);
}

void My_Error(char error_text[])
{
	printf("\n\nFatal Error ...\n\n");
	printf("%s\n",error_text);
	printf("...now exiting...\n\n");
	exit(-1);
}

/* skiptoend - routine to read comments in data file up to end of line */
void skiptoend(FILE *fp)
{
	register int    c;
	while ((c = getc(fp)) != EOF && c != '\n');
}



float ran4(long *idum);

long my_idum;

long my_idum_action_selection,Memorize_my_idum_action_selection;

void Reset_Random_Seed_For_Paths(void)
{
	Memorize_my_idum_action_selection = (long)(10000000 * ran4(&my_idum));
}
double My_Rand_Action_Selection(void)
{
	return(ran4(&my_idum_action_selection));
}

void My_Seed_Rand_Action_Selection(void)
{
	//my_idum = (unsigned)time( NULL );
	my_idum_action_selection = Memorize_my_idum_action_selection;
}

double My_Rand(void)
{
	return(ran4(&my_idum));
}

void My_Seed_Rand(void)
{
	my_idum = (unsigned)time( NULL );
	my_idum_action_selection = (unsigned)time( NULL );
	//my_idum = 12345;
	//my_idum_action_selection = 123456;
	Memorize_my_idum_action_selection = my_idum_action_selection;
}
void My_Seed_Rand_Fixed(void)
{
	my_idum = 345;
	my_idum_action_selection = 3456;
	Memorize_my_idum_action_selection = my_idum_action_selection;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?