Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 逻辑:如何在C/C中打印伪随机位序列模式++_C++_C - Fatal编程技术网

C++ 逻辑:如何在C/C中打印伪随机位序列模式++

C++ 逻辑:如何在C/C中打印伪随机位序列模式++,c++,c,C++,C,真的,我想得到随机位序列模式,请告诉我如何得到序列模式的逻辑 我尝试使用下面的示例代码来获得这样的随机位序列模式 2147483663, 1073741831, 536870915, 2415919105, 1207959552, 2751463424, 3523215360, 1761607680, 3028287488, 3661627392, 1830813696 1932117999, 1932117999, 1932117999, 1932117999, 1932117999, 19

真的,我想得到随机位序列模式,请告诉我如何得到序列模式的逻辑

我尝试使用下面的示例代码来获得这样的随机位序列模式

2147483663, 1073741831, 536870915, 2415919105, 1207959552, 2751463424, 3523215360, 1761607680, 3028287488, 3661627392, 1830813696
1932117999, 1932117999, 1932117999, 1932117999, 1932117999, 1932117999, 1932117999, 1932117999, 1932117999, 1932117999
但我得到的只是一个常数,没有像这样的变化

2147483663, 1073741831, 536870915, 2415919105, 1207959552, 2751463424, 3523215360, 1761607680, 3028287488, 3661627392, 1830813696
1932117999, 1932117999, 1932117999, 1932117999, 1932117999, 1932117999, 1932117999, 1932117999, 1932117999, 1932117999
请找到附件并向我推荐。我很感激

int main()
{
  unsigned int x=12131222, y=898565;
  unsigned int z=58964796, c=6543217;
  unsigned long long t, result;
  unsigned int r;
  int i;

  x = 14900243 * x+ 123456789;
  y ^= y << 21;
  y ^= y >> 17;
  y ^= y << 30;

  /* Do not set y=0! */

  t = 42945843 * z + c;
  c = t >> 32;
  z = t;

  result=(unsigned int)(x>>32) + (unsigned int)y +z;

  for ( i = 0; i < 10; i++) 
  {
    r = result; //use the LFSR
    printf ("%u, ", r);
  }

  return 0;
}

首先,为它创建特殊的功能。 其次,在每次迭代中使用静态变量保存进度

#include <stdio.h>

unsigned long long random()
{
        static unsigned int x =12131222, y=898565;
        static unsigned int z=58964796, c=6543217;
        unsigned long long t, result;
        x = 14900243 * x+ 123456789;
        y ^= y << 21;
        y ^= y >> 17;
        y ^= y << 30;
        /* Do not set y=0! */
        t = 42945843 * z + c;
        c = t >> 32;
        z = t;
        return result=(unsigned int)(x>>32) + (unsigned int)y +z;
}
int main()
{
        unsigned int r;
        int i;
        for ( i = 0; i < 10; i++)
        {
                r = random(); //use the LFSR
                printf ("%u, ", r);
        }
        return 0;
}
或者将代码移动到循环中:

#include <stdio.h>

int main()
{
        unsigned int x =12131222, y=898565;
        unsigned int z=58964796, c=6543217;
        unsigned long long t, result;

        unsigned int r;
        int i;
        for ( i = 0; i < 10; i++)
        {
                x = 14900243 * x+ 123456789;
                y ^= y << 21;
                y ^= y >> 17;
                y ^= y << 30;
                /* Do not set y=0! */
                t = 42945843 * z + c;
                c = t >> 32;
                z = t;
                result=(unsigned int)(x>>32) + (unsigned int)y +z;
                r = result; //use the LFSR
                printf ("%u, ", r);
        }
        return 0;
}

通常,您不应该编写自己的伪随机数代码。使用srand进行种子设定,使用rand进行计算,如下所示:
仍然有质量更好的随机数选项,但这是一个起点。

循环不会修改结果,只会打印10次。价值应该如何变化?每次执行循环时都需要执行操作;需要使用更广泛的数学和t=42945843*z+c;仅为t指定了无符号范围内的值。同样,需要更广泛的数学知识。您的LFSR算法的源代码是什么?我可以使用寄存器概念来表示随机位序列模式吗。实际上我需要在硬件上实现这个程序。源代码'void多项式\u lfsrint&dout{static int reg;int pattern;int load_data=0xACF5;int i=0;reg=load_data;for i=0;i>0^reg>>2^reg>>3^reg>>5&1;reg=reg>>1位我不能在VIVADO HLS中使用srand。所以我正在尝试LFSR。不过,您需要考虑种子设定。我可以使用寄存器概念来实现随机位序列模式吗?实际上我需要用硬件实现这个程序。源代码`void polymonal\u lfsrint&dout{static int reg;int pattern;int load\u data=0xACF5;int i=0;reg=load\u data;for i=0;i>0^reg>>2^reg>>3^reg>>5&1;reg=reg>>1位更新问题。如果没有格式化,代码很难理解