从这集开始, 做一些综合的实验. 因为基础指令已经在以前的几篇中介绍完了.本集介绍两个实验: 随机数生成与点乘积
1.随机数生成
C语言获取随机数, 最为常见就是调用rand函数. 这个函数是C Lib的一部分, 还有配套的srand配置随机数种子.
extern _ARMABI int rand(void);
/*
* Computes a sequence of pseudo-random integers in the range 0 to RAND_MAX.
* Uses an additive generator (Mitchell & Moore) of the form:
* Xn = (X[n-24] + X[n-55]) MOD 2^31
* This is described in section 3.2.2 of Knuth, vol 2. It's period is
* in excess of 2^55 and its randomness properties, though unproven, are
* conjectured to be good. Empirical testing since 1958 has shown no flaws.
* Returns: a pseudo-random integer.
*/
extern _ARMABI void srand(unsigned int /*seed*/);
/*
* uses its argument as a seed for a new sequence of pseudo-random numbers
* to be returned by subsequent calls to rand. If srand is then called with
* the same seed value, the sequence of pseudo-random numbers is repeated.
* If rand is called before any calls to srand have been made, the same
* sequence is generated as when srand is first called with a seed value
* of 1.
*/
这种随机数属于软件实现, 事实上大多数低功耗,低计算力的内核都没有真随机数发生器.所谓真随机数生成器要依赖于真正的随机源,如热噪音.
只有注册用户才能在此添加评论。 如果您已经注册,请登录。 如果您还没有注册,请注册并登录。