使用线性同余法生成伪随机数/序列(C++实现)2

以下是网上关于随机数生成的一类说法:

在计算机上可以用物理方法来产生随机数,但价格昂贵,不能重复,使用不便。另一种方法是用数学递推公式产生,这样产生的序列与真正的随机数序列不同,所以称为伪随机数或伪随机序列,只要方法和参数选择合适,所产生的伪随机数就能满足均匀性和独立性,与真正的随机数具有相近的性质。

以下是一个使用了线性同余的递推公式:

Xt = (X0 * 17 + 29) mod 500

线性同余中的线性,是指“线性”表示方程中 x 的次数是一次,mod 取余运算符则体现了“同余”这一数学概念。

式中,17 、29和500分别称做乘数、增量和模数。使用线性同余生成随机数的方法速度快,但对乘数、增量和模数的选取有一定的要求:

  1. 多次使用线性同余公式产生的序列应该看起来是随机的,不循环的;
  2. 乘数/增量与模数互质;
  3. 这个函数能够产生一个完整周期内的所有随机数。这一要求由模数控制。
<code class="hljs cpp has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#include <ctime></span>
<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#include <iostream></span>

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">class</span> MyRand
{
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span>:
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">unsigned</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> seed;

    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 默认使用系统时间为种子</span>
    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// time(NULL) 返回从1970年元旦午夜0点到现在的秒数</span>
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> srand(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">unsigned</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> s = (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">unsigned</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span>)time(NULL))
    {
        seed = s;
    }

    <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 使用了一种线性同余法,得到的随机数最大为(2^15-1),29为质数中的一个</span>
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">unsigned</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> rand()
    {
        seed = (seed * <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">31</span> + <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">13</span>) % ((<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> << <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">15</span>) - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>);
        <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> seed;
    }
};
</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li></ul>
<code class="hljs cpp has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">#include "rand.h"</span>

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> main()
{
    MyRand a;

    a.srand();  <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 使用系统时间为种子</span>

    <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">std</span>::<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">cout</span> << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"产生若干个随机数:"</span> << <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">std</span>::endl;
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> i = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>; i < <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">100</span>; i++)
        <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">std</span>::<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">cout</span> << a.rand() % <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">100</span> << <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">" "</span>;  <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">// 生成0~100之间的随机数</span>

    getchar();
    <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
}</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li></ul>

使用错误的公式,得到的序列并不随机:

http://huisheng.fm/user/view/25853

http://huisheng.fm/user/view/25853

http://huisheng.fm/user/view/25855

http://huisheng.fm/user/view/25856

http://huisheng.fm/user/view/25857

http://huisheng.fm/user/view/25858

http://huisheng.fm/user/view/25859

http://huisheng.fm/user/view/25860

http://huisheng.fm/user/view/25861

http://huisheng.fm/user/view/25862

http://huisheng.fm/user/view/25863

http://huisheng.fm/user/view/25864

http://huisheng.fm/user/view/25865

http://huisheng.fm/user/view/25866

http://huisheng.fm/user/view/25867

http://huisheng.fm/user/view/25868

http://huisheng.fm/user/view/25869

http://huisheng.fm/user/view/25870

http://huisheng.fm/user/view/25871

http://huisheng.fm/user/view/25872

http://huisheng.fm/user/view/25873

http://huisheng.fm/user/view/25874

http://huisheng.fm/user/view/25875

http://huisheng.fm/user/view/25876

http://huisheng.fm/user/view/25877

http://huisheng.fm/user/view/25878

http://huisheng.fm/user/view/25879

http://huisheng.fm/user/view/25880

http://huisheng.fm/user/view/25881

http://huisheng.fm/user/view/25882

http://huisheng.fm/user/view/25883

http://huisheng.fm/user/view/25884

http://huisheng.fm/user/view/25885

http://huisheng.fm/user/view/25886

http://huisheng.fm/user/view/25887

http://huisheng.fm/user/view/25888

http://huisheng.fm/user/view/25889

http://huisheng.fm/user/view/25890

http://huisheng.fm/user/view/25891

http://huisheng.fm/user/view/25892

http://huisheng.fm/user/view/25893

http://huisheng.fm/user/view/25894

http://huisheng.fm/user/view/25895

http://huisheng.fm/user/view/25896

http://huisheng.fm/user/view/25897

http://huisheng.fm/user/view/25898

http://huisheng.fm/user/view/25899

http://huisheng.fm/user/view/25900

http://huisheng.fm/user/view/25901

http://huisheng.fm/user/view/25902

http://huisheng.fm/user/view/25903

http://huisheng.fm/user/view/25904

http://huisheng.fm/user/view/25905

http://huisheng.fm/user/view/25906

http://huisheng.fm/user/view/25907

http://huisheng.fm/user/view/25908

http://huisheng.fm/user/view/25909

http://huisheng.fm/user/view/25910

http://huisheng.fm/user/view/25911

http://huisheng.fm/user/view/25912

http://huisheng.fm/user/view/25913

http://huisheng.fm/user/view/25914

http://huisheng.fm/user/view/25915

http://huisheng.fm/user/view/25916

http://huisheng.fm/user/view/25917

http://huisheng.fm/user/view/25918

http://huisheng.fm/user/view/25919

http://huisheng.fm/user/view/25920

http://huisheng.fm/user/view/25921

http://huisheng.fm/user/view/25922

http://huisheng.fm/user/view/25923

http://huisheng.fm/user/view/25924

http://huisheng.fm/user/view/25925

http://huisheng.fm/user/view/25926

http://huisheng.fm/user/view/25927

http://huisheng.fm/user/view/25928

http://huisheng.fm/user/view/25929

http://huisheng.fm/user/view/25930

http://huisheng.fm/user/view/25931

http://huisheng.fm/user/view/25932

http://huisheng.fm/user/view/25933

http://huisheng.fm/user/view/25934

http://huisheng.fm/user/view/25935

http://huisheng.fm/user/view/25936

http://huisheng.fm/user/view/25937

http://huisheng.fm/user/view/25938

http://huisheng.fm/user/view/25939

http://huisheng.fm/user/view/25940

http://huisheng.fm/user/view/25941

http://huisheng.fm/user/view/25942

http://huisheng.fm/user/view/25943

http://huisheng.fm/user/view/25944

http://huisheng.fm/user/view/25945

http://huisheng.fm/user/view/25946

http://huisheng.fm/user/view/25947

http://huisheng.fm/user/view/25948

http://huisheng.fm/user/view/25949

http://huisheng.fm/user/view/25950

http://huisheng.fm/user/view/25951

http://huisheng.fm/user/view/25952

http://huisheng.fm/user/view/25953

http://huisheng.fm/user/view/25954

http://huisheng.fm/user/view/25955

http://huisheng.fm/user/view/25956

http://huisheng.fm/user/view/25957

http://huisheng.fm/user/view/25958

http://huisheng.fm/user/view/25959

http://huisheng.fm/user/view/25960

http://huisheng.fm/user/view/25961

http://huisheng.fm/user/view/25962

http://huisheng.fm/user/view/25963

http://huisheng.fm/user/view/25964

http://huisheng.fm/user/view/25965

http://huisheng.fm/user/view/25966

http://huisheng.fm/user/view/25967

http://huisheng.fm/user/view/25968

http://huisheng.fm/user/view/25969

http://huisheng.fm/user/view/25970

http://huisheng.fm/user/view/25971

http://huisheng.fm/user/view/25972

http://huisheng.fm/user/view/25973

http://huisheng.fm/user/view/25974

http://huisheng.fm/user/view/25975

http://huisheng.fm/user/view/25976

http://huisheng.fm/user/view/25977

http://huisheng.fm/user/view/25978

http://huisheng.fm/user/view/25979

http://huisheng.fm/user/view/25980

http://huisheng.fm/user/view/25981

http://huisheng.fm/user/view/25982

http://huisheng.fm/user/view/25983

http://huisheng.fm/user/view/25984

http://huisheng.fm/user/view/25985

http://huisheng.fm/user/view/25986

http://huisheng.fm/user/view/25987

http://huisheng.fm/user/view/25988

http://huisheng.fm/user/view/25989

http://huisheng.fm/user/view/25990

http://huisheng.fm/user/view/25991

http://huisheng.fm/user/view/25992

http://huisheng.fm/user/view/25993

http://huisheng.fm/user/view/25994

http://huisheng.fm/user/view/25995

http://huisheng.fm/user/view/25996

http://huisheng.fm/user/view/25997

http://huisheng.fm/user/view/25998

http://huisheng.fm/user/view/25999

http://huisheng.fm/user/view/26000

http://huisheng.fm/user/view/26001

http://huisheng.fm/user/view/26002

http://huisheng.fm/user/view/26003

http://huisheng.fm/user/view/26004

http://huisheng.fm/user/view/26005

http://huisheng.fm/user/view/26006

http://huisheng.fm/user/view/26007

http://huisheng.fm/user/view/26008

http://huisheng.fm/user/view/26009

http://huisheng.fm/user/view/26010

http://huisheng.fm/user/view/26011

http://huisheng.fm/user/view/26012

http://huisheng.fm/user/view/26013

http://huisheng.fm/user/view/26014

http://huisheng.fm/user/view/26015

http://huisheng.fm/user/view/26016

http://huisheng.fm/user/view/26017

http://huisheng.fm/user/view/26018

http://huisheng.fm/user/view/26019

http://huisheng.fm/user/view/26020

http://huisheng.fm/user/view/26021

http://huisheng.fm/user/view/26022

http://huisheng.fm/user/view/26024

http://huisheng.fm/user/view/26025

http://huisheng.fm/user/view/26026

http://huisheng.fm/user/view/26027

http://huisheng.fm/user/view/26028

http://huisheng.fm/user/view/26029

http://huisheng.fm/user/view/26030

http://huisheng.fm/user/view/26031

http://huisheng.fm/user/view/26032

http://huisheng.fm/user/view/26033

http://huisheng.fm/user/view/26034

http://huisheng.fm/user/view/26035

http://huisheng.fm/user/view/26036

http://huisheng.fm/user/view/26037

http://huisheng.fm/user/view/26038

http://huisheng.fm/user/view/26039

http://huisheng.fm/user/view/26040

http://huisheng.fm/user/view/26041

http://huisheng.fm/user/view/26042

http://huisheng.fm/user/view/26043

http://huisheng.fm/user/view/26044

http://huisheng.fm/user/view/26045

http://huisheng.fm/user/view/26046

http://huisheng.fm/user/view/26047

http://huisheng.fm/user/view/26048

http://huisheng.fm/user/view/26049

http://huisheng.fm/user/view/26050

http://huisheng.fm/user/view/26051

http://huisheng.fm/user/view/26052

http://huisheng.fm/user/view/26053

http://huisheng.fm/user/view/26054

http://huisheng.fm/user/view/26055

http://huisheng.fm/user/view/26056

http://huisheng.fm/user/view/26057

http://huisheng.fm/user/view/26058

http://huisheng.fm/user/view/26059

http://huisheng.fm/user/view/26060

http://huisheng.fm/user/view/26061

http://huisheng.fm/user/view/26062

http://huisheng.fm/user/view/26063

http://huisheng.fm/user/view/26064

http://huisheng.fm/user/view/26065

http://huisheng.fm/user/view/26066

http://huisheng.fm/user/view/26067

http://huisheng.fm/user/view/26068

http://huisheng.fm/user/view/26069

http://huisheng.fm/user/view/26070

http://huisheng.fm/user/view/26071

http://huisheng.fm/user/view/26072

http://huisheng.fm/user/view/26073

http://huisheng.fm/user/view/26074

http://huisheng.fm/user/view/26075

http://huisheng.fm/user/view/26076

http://huisheng.fm/user/view/26077

http://huisheng.fm/user/view/26078

http://huisheng.fm/user/view/26079

http://huisheng.fm/user/view/26080

http://huisheng.fm/user/view/26081

http://huisheng.fm/user/view/26082

http://huisheng.fm/user/view/26083

http://huisheng.fm/user/view/26084

http://huisheng.fm/user/view/26085

http://huisheng.fm/user/view/26086

http://huisheng.fm/user/view/26087

http://huisheng.fm/user/view/26088

http://huisheng.fm/user/view/26089

http://huisheng.fm/user/view/26090

http://huisheng.fm/user/view/26091

http://huisheng.fm/user/view/26092

http://huisheng.fm/user/view/26093

http://huisheng.fm/user/view/26094

http://huisheng.fm/user/view/26095

http://huisheng.fm/user/view/26096

http://huisheng.fm/user/view/26097

http://huisheng.fm/user/view/26098

http://huisheng.fm/user/view/26099

http://huisheng.fm/user/view/26100

http://huisheng.fm/user/view/26101

http://huisheng.fm/user/view/26102

http://huisheng.fm/user/view/26103

http://huisheng.fm/user/view/26104

http://huisheng.fm/user/view/26105

http://huisheng.fm/user/view/26106

http://huisheng.fm/user/view/26107

http://huisheng.fm/user/view/26108

http://huisheng.fm/user/view/26109

http://huisheng.fm/user/view/26110

http://huisheng.fm/user/view/26111

http://huisheng.fm/user/view/26112

http://huisheng.fm/user/view/26113

http://huisheng.fm/user/view/26114

http://huisheng.fm/user/view/26115

http://huisheng.fm/user/view/26116

http://huisheng.fm/user/view/26117

http://huisheng.fm/user/view/26118

http://huisheng.fm/user/view/26119

http://huisheng.fm/user/view/26120

http://huisheng.fm/user/view/26121

http://huisheng.fm/user/view/26122

http://huisheng.fm/user/view/26123

http://huisheng.fm/user/view/26124

http://huisheng.fm/user/view/26125

http://huisheng.fm/user/view/26126

http://huisheng.fm/user/view/26127

http://huisheng.fm/user/view/26128

http://huisheng.fm/user/view/26129

http://huisheng.fm/user/view/26130

http://huisheng.fm/user/view/26131

http://huisheng.fm/user/view/26132

http://huisheng.fm/user/view/26133

http://huisheng.fm/user/view/26134

http://huisheng.fm/user/view/26135

http://huisheng.fm/user/view/26136

http://huisheng.fm/user/view/26137

http://huisheng.fm/user/view/26138

http://huisheng.fm/user/view/26139

http://huisheng.fm/user/view/26140

http://huisheng.fm/user/view/26141

http://huisheng.fm/user/view/26142

http://huisheng.fm/user/view/26143

http://huisheng.fm/user/view/26144

http://huisheng.fm/user/view/26145

http://huisheng.fm/user/view/26146

http://huisheng.fm/user/view/26147

http://huisheng.fm/user/view/26148

http://huisheng.fm/user/view/26149

http://huisheng.fm/user/view/26150

http://huisheng.fm/user/view/26151

http://huisheng.fm/user/view/26152

http://huisheng.fm/user/view/26153

http://huisheng.fm/user/view/26154

http://huisheng.fm/user/view/26155

http://huisheng.fm/user/view/26156

http://huisheng.fm/user/view/26157

http://huisheng.fm/user/view/26158

http://huisheng.fm/user/view/26159

http://huisheng.fm/user/view/26160

http://huisheng.fm/user/view/26161

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-12-14 10:10:59

使用线性同余法生成伪随机数/序列(C++实现)2的相关文章

使用线性同余法生成伪随机数/序列(C++实现)

最近朋友提出一个问题,自己编写函数生成随机数,一开始没有认真思考,后来想了一下,如果是学习过计算机密码学,应该很快就能设计出一些算法,这里使用了数论领域的相关知识--线性同余法简单实现了生成随机数算法. 以下是网上关于随机数生成的一类说法: 在计算机上可以用物理方法来产生随机数,但价格昂贵,不能重复,使用不便.另一种方法是用数学递推公式产生,这样产生的序列与真正的随机数序列不同,所以称为伪随机数或伪随机序列,只要方法和参数选择合适,所产生的伪随机数就能满足均匀性和独立性,与真正的随机数具有相近的

线性同余法的伪随机数

学校练习,简单的我就不放上来了,值得整理的,我保存一下 习题9 1.1. 伪随机数(线性同余法)   1.1.1.算法描述 我们使用线性同余法,来限定一些离散点在y=a*x+b上. 1.1.2.伪代码   random(n,m,seed,a,b) //根据现行同余法生成n个伪随机书的一个序列 //输入:一个正整数n和正整数参数m,seed,a,b //输出:随机数组 r0<-seed for i<-1 to n do ri<-(a*ri-1+b) mod m end 1.1.3.算法实现

伪随机数算法--线性同余法

1 Static Function rand() 2 x = (x * 37 + 27) Mod 1000 3 rand = x 4 End Function VB代码 伪随机数算法--线性同余法

Matlab生成M序列的伪随机码

伪随机编码中较常用的是m序列,它是线性反馈移位寄存器序列的一种,其特点是在相同寄存器级数的情况下输出序列周期最长.线性反馈移位寄存器的工作原理是,给定所有寄存器一个初始值,当移位脉冲到来时,将最后一级寄存器的值输出,同时将第 i级的寄存器内容存储到第 i+1 级中,此外将每一级的寄存器输出按照一定的线性运算规则计算出一个值,并将该值存入第一级寄存器中.随着移位脉冲的累加,线性反馈移位寄存器的输出可以组成一个序列,称之为移位寄存器序列[71]. 图3.5 线性反馈移位寄存器 MATLAB生成M序列

生成数字序列命令(7)

生成数字序列命令:seq,shuf 7.1.seq 功能:打印数字序列 语法:seq [OPTION]... LAST seq [OPTION]... FIRST LAST seq [OPTION]... FIRST INCREMENT LAST 常用选项: -f  使用printf样式格式 -s  指定分隔符,默认换行符\n -w  等宽,用0填充 示例: 数字序列: 方法1: [[email protected] ~]# seq 10 1 2 3 4 5 6 7 8 9 10 方法2: fo

扩增子分析解读4去嵌合体 非细菌序列 生成代表性序列和OTU表

本节课程,需要先完成 扩增子分析解读1质控 实验设计 双端序列合并 2提取barcode 质控及样品拆分 切除扩增引物 3格式转换 去冗余 聚类 先看一下扩增子分析的整体流程,从下向上逐层分析 分析前准备 # 进入工作目录 cd example_PE250 上一节回顾:我们制作了Usearch要求格式的Fasta文件,对所有序列进行去冗余和低丰度过滤,并聚类生成了OTU. 接下来我们对OTU进一步去除嵌合体,并生成代表性序列和OTU表. 什么是chimeras(嵌合体)? 嵌合体序列由来自两条或

关于用 random 生成伪随机数的一个手笔

我在想还要不要写什么文字.确实不需要太多的文字描述吧. 前奏插一个小话题,之前在网上看到这样的冷笑话(有图的),一个程序猿调试个程序,早上怀疑某某地方的错误,下午怀疑某某地方的错误,晚上怀疑某某地方可能错了,睡觉了还是辗转反侧难以入眠.第二天早上,再看看代码的时候,无意中找到了bug,漏下了逗号“,“,哈哈冷笑话. 我这次也是疏忽了.在一个网站的项目中,用random去生成随机数,作为上传文件的名称.当然在需要用户上传的文件中是不容易遇到这个bug的.但是在做爬虫下载文件也用这个random生成

使用递归算法生成一个序列

--功能:使用递归算法生成一个序列 --日期:2019-11-30 --作者a:ligq --功能:1.生成等差数列 DECLARE @ib INT = 1; --第一项的值 DECLARE @ig INT = 2; --公差 DECLARE @imax INT = 100; --序列中的最大值 WITH ctea (i) AS (SELECT @ib AS i UNION ALL SELECT i + @ig --这里修改公差 FROM ctea WHERE i <= @imax - @ig)

Pytorch基础——使用 RNN 生成简单序列

一.介绍 内容 使用 RNN 进行序列预测 今天我们就从一个基本的使用 RNN 生成简单序列的例子中,来窥探神经网络生成符号序列的秘密. 我们首先让神经网络模型学习形如 0^n 1^n 形式的上下文无关语法.然后再让模型尝试去生成这样的字符串.在流程中将演示 RNN 及 LSTM 相关函数的使用方法. 实验知识点 什么是上下文无关文法 使用 RNN 或 LSTM 模型生成简单序列的方法 探究 RNN 记忆功能的内部原理 二.什么是上下文无关语法 上下文无关语法 首先让我们观察以下序列: 01 0