⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rand.c

📁 nsga2具体算法代码,用来多目标遗传算法的学习和研究
💻 C
字号:
/* Definition of random number generation routines */# include <stdio.h># include <stdlib.h># include <math.h># include "global.h"# include "rand.h"double seed;double oldrand[55];int jrand;/* Get seed number for random and start it up */void randomize(){    int j1;    for(j1=0; j1<=54; j1++)    {        oldrand[j1] = 0.0;    }    jrand=0;    warmup_random (seed);    return;}/* Get randomize off and running */void warmup_random (double seed){    int j1, ii;    double new_random, prev_random;    oldrand[54] = seed;    new_random = 0.000000001;    prev_random = seed;    for(j1=1; j1<=54; j1++)    {        ii = (21*j1)%54;        oldrand[ii] = new_random;        new_random = prev_random-new_random;        if(new_random<0.0)        {            new_random += 1.0;        }        prev_random = oldrand[ii];    }    advance_random ();    advance_random ();    advance_random ();    jrand = 0;    return;}/* Create next batch of 55 random numbers */void advance_random (){    int j1;    double new_random;    for(j1=0; j1<24; j1++)    {        new_random = oldrand[j1]-oldrand[j1+31];        if(new_random<0.0)        {            new_random = new_random+1.0;        }        oldrand[j1] = new_random;    }    for(j1=24; j1<55; j1++)    {        new_random = oldrand[j1]-oldrand[j1-24];        if(new_random<0.0)        {            new_random = new_random+1.0;        }        oldrand[j1] = new_random;    }}/* Fetch a single random number between 0.0 and 1.0 */double randomperc(){    jrand++;    if(jrand>=55)    {        jrand = 1;        advance_random();    }    return((double)oldrand[jrand]);}/* Fetch a single random integer between low and high including the bounds */int rnd (int low, int high){    int res;    if (low >= high)    {        res = low;    }    else    {        res = low + (randomperc()*(high-low+1));        if (res > high)        {            res = high;        }    }    return (res);}/* Fetch a single random real number between low and high including the bounds */double rndreal (double low, double high){    return (low + (high-low)*randomperc());}

⌨️ 快捷键说明

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