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

📄 rand.c

📁 多目标算法的DSP实现。可以直接在DSP平台上进行多目标优化
💻 C
字号:
// 随机数发生器# include <stdio.h># include <math.h>
# include "malloc.h"# include "global.h"double seed;double oldrand[55];int jrand;// 生成种子void randomize(){    int j1;    for(j1=0; j1<=54; j1++)    {        oldrand[j1] = 0.0;    }    jrand=0;    warmup_random (seed);    return;}// 准备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;}// 生成下一批随机数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;    }}// 生成(0-1)之间的随机数double randomperc(){    jrand++;    if(jrand>=55)    {        jrand = 1;        advance_random();    }    return ((double)oldrand[jrand]);}// 生成[low, high]之间的整数随机数(包括边界)int rand_integer (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);}// 生成[low, high]之间的实数随机数double rand_real (double low, double high){    return (low + (high-low)*randomperc());}

⌨️ 快捷键说明

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