小编joh*_*eef的帖子

如何每n次重置一个函数变量?

我使用的是随机数生成功能,它的工作很好,但我需要重置功能变量nSeedñ倍,假设nSeed = 5323 ..我怎么能恢复到它的初始值5323每隔5个操作我不是确定怎么做..这是一个例子:

unsigned int PRNG()  

{  
    static unsigned int nSeed = 5323;  
    nSeed = (8253729 * nSeed + 2396403);  
    return nSeed  % 32767;
}  

int main()
{
   int count=0;  
   while(count<10)  
   {  
       count=count+1;  
       cout<<PRNG()<<endl;  

          if(count==5)
          {  
               nSeed= 5323;   //here's the problem, "Error nSeed wasn't declared in the scoop"
          } 
   }  
}  
Run Code Online (Sandbox Code Playgroud)

注意:我需要在scoop中声明计数器,而不是在函数中.

c++ variables static

1
推荐指数
1
解决办法
76
查看次数

标签 统计

c++ ×1

static ×1

variables ×1