zoukankan      html  css  js  c++  java
  • Matlab rand randn randint

    1.0matlab中rand函数是产生0到1的随机分布
    2.0matlab中randn函数是产生标准正态分布
    3.0randint是产生整数随机数,默认为0和1
    1.0rand

    %%%%%%%%%%%rand%%%%%%%%%%%%%%%%
        RAND   Uniformly distributed random numbers.    标准化分布的随机数
        RAND(N) is an N-by-N matrix with random entries, chosen from a uniform distribution on the interval (0.0,1.0).   rand(N)为随机生成一个在【0,1】之间的n维随机矩阵。
        RAND(M,N) and RAND([M,N]) are M-by-N matrices with random entries.随机生成一个在【0,1】之间的m,n维随机矩阵。
        RAND(M,N,P,...) or RAND([M,N,P,...]) generate random arrays.
        RAND with no arguments is a scalar whose value changes each time it  is referenced. RAND(SIZE(A)) is the same size as A.
     
        RAND produces pseudo-random numbers.  The sequence of numbers  generated is determined by the state of the generator.  Since MATLAB  resets the state at start-up, the sequence of numbers generated will  be the same unless the state is changed.  matlab的随机数算法是通过一个“种子”递推出来的,种子在程序初始的时候都一样。
        S = RAND('state') is a 35-element vector containing the current state  of the uniform generator.  RAND('state',S) resets the state to S.
        RAND('state',0) resets the generator to its initial state. 重新恢复初始状态,刚运行matlab时候的状态
        RAND('state',J), for integer J, resets the generator to its J-th state. 安排种子产生第j个状态
        RAND('state',sum(100*clock)) resets it to a different state each time.根据时间产生不同的随机数
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     

    2.0randn

    %%%%%%%%%%%%%%%%%%randn%%%%%%%%%%%

    (1)RANDN产生正态分布数的语法:
    RANDN(N) :产生N× N的矩阵,其元素是按正态分布的数组;
    RANDN(M,N) and RANDN([M,N]):产生M×N的矩阵;
    RANDN(M,N,P,...) or RANDN([M,N,P...])产生随机序列;

    (2)RANDN产生伪随机数的语法:
    发生器的状态决定所产生数的序号。
    S = RANDN('state') 是一个二元向量,包括标准发生器的状态;
    RANDN('state',S):设置发生器的状态为S(即标准状态);
    RANDN('state',0):设置发生器的初始状态;
    RANDN('state',J):J为整数,设置发生器到J阶状态;

    (3)MATlAB 4.X应用一个单独的种子来产生随机数:
    RANDN('seed',0) and RANDN('seed',J)作用与RANDN('state',0)和RANDN('state',J)一样,但使用Matlab 4.x随机数发生器。
    RANDN('seed'):返回MATlAB 4.X发生器的当前种子。

    %%%%%%%%%%%%%%%%%%randn%%%%%%%%%%%

  • 相关阅读:
    手写简易SpringMVC框架,包含@PathVariable
    高并发下,如何保证接口的幂等性?
    JAVA判断奇偶数
    多线程ForkJoin-分治思想
    websocket简单使用
    Git使用教程:最详细、最傻瓜、最浅显、真正手把手教!(转载学习)
    linux配置java环境变量(详细)
    java缓存技术的介绍(转载)
    java 多态性详解及常见面试题
    oracle数据库基础知识总结(一)
  • 原文地址:https://www.cnblogs.com/jhonsonwanger/p/4378979.html
Copyright © 2011-2022 走看看