公告

大中华汽车电子生态圈社区并入开发者社区- 更多资讯点击此

Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

Cortex M处理器汇编语言编程之五:随机数生成,点乘积

Cortex M处理器汇编语言编程之五:随机数生成,点乘积

User12775
Level 5
Level 5
First solution authored First like received

从这集开始, 做一些综合的实验. 因为基础指令已经在以前的几篇中介绍完了.本集介绍两个实验: 随机数生成与点乘积

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.

*/

这种随机数属于软件实现, 事实上大多数低功耗,低计算力的内核都没有真随机数发生器.所谓真随机数生成器要依赖于真正的随机源,如热噪音.

0 点赞
2785 次查看
6 评论