c_cpp 伪随机生成的假数据用于测试内部工具

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 伪随机生成的假数据用于测试内部工具相关的知识,希望对你有一定的参考价值。

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

int main(void)
{
    char *op[2] = {"read", "write"};
    srand(time(0)); //use current time as seed for random generator
    int pause, linect, rout, r = 0;
    // Print header
    printf("source,cmd,path,IOs,lat.ns,min.lat.ns,max.lat.ns,bytes,max_bytes\n");

    // Loop until killed producing pseudo randomly generated NFS metric samples
    while (1) {
      rout = rand();
      pause = time(0)%10;
      linect = rout%100;
      // We expect that about 5 percent of the time rout%100 will fall between
      // 30 and 35. When this happens we want to make our pause unusually long
      // which we set to rout%100 here, instead of using: pause = time(0)%10;
      if (rout%100 >= 30 && rout%100 < 35) pause = rout%100;
      while (linect-- > 0) {
        r = rand();
        // columns: str,str,str,int,int,int,int,int,int
	      printf("10.1.100.2,%s,/storage/p01/global/x%d,%d,%d,%d,%d,%d,%d\n",
	        op[r%2 == 0], r%30, r%99<<3, r/2, r, r, r, r);
      }
      sleep(pause);
    }

    return 0;
}

以上是关于c_cpp 伪随机生成的假数据用于测试内部工具的主要内容,如果未能解决你的问题,请参考以下文章

java伪随机数生成器

将具有随机生成的假数据的动态数据帧转换为静态数据帧

python3 测试的时候如何批量随机生成伪数据?(faker模块的)

伪随机数

伪随机目录树生成?

随机生成测试数据<faker模块的基本使用;