- 浏览: 539980 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
GGGGeek:
看完了博主的博文,如果没猜错的话应该是浙大吧?很多优秀的人因为 ...
转《D君的故事》 以时刻警示自己 -
游牧民族:
楼主写的不错,学习了,最近对爬虫比较感兴趣,也写了些爬虫相关的 ...
通用爬虫框架及heritrix爬虫介绍 -
jimmee:
jerome_s 写道ice 你怎么看? 粗略的看了一下ice ...
MessagePack, Protocol Buffers和Thrift序列化框架原理和比较说明 -
jerome_s:
ice 你怎么看?
MessagePack, Protocol Buffers和Thrift序列化框架原理和比较说明 -
jimmee:
nk_tocean 写道照着做了,但是不行啊,还是乱码.先确认 ...
hive编写udf处理非utf-8数据
(转载)Pseudo-Random Number Generation Routine for the MAX765x Microprocessor
- 博客分类:
- J2SE
Abstract: This application note gives a function for random number generation using the MAX7651/52 microcontroller with 12-bit analog-to-digital converter (ADC).
Applications such as spread-spectrum communications, security, encryption and modems require the generation of random numbers. The most common way to implement a random number generator is a Linear Feedback Shift Register (LFSR). Codes generated by a LFSR are actually "pseudo" random, because after some time the numbers repeat. The trick is to use a shift register of sufficient length so that the pattern repeats after some extremely long time.
A basic LFSR of length five is shown in Figure 1. The shift register is a series-connected group of flip-flops, with XOR feedback. An XOR gate is use to scramble the input bit.
Figure 1. 5-stage linear feedback shift register.
Figure 1. 5-stage linear feedback shift register.
There are tables that give the proper feedback tap position for generating sequences that take the maximum number of clocks to repeat. Such a table is shown below:
Table 1. Taps for Maximal-Length LFSRs with 2 to 32 Bits
No. of bits Length of Loop Taps
2 3* [0,1]
3 7* [0,2]
4 15 [0,3]
5 31* [1,4]
6 63 [0,5]
7 127* [0,6]
8 255 [1,2,3,7]
9 511 [3,8]
10 1023 [2,9]
11 2047 [1,10]
12 4095 [0,3,5,11]
13 8191* [0,2,3,12]
14 16,383 [0,2,4,13]
15 32,767 [0,14]
16 65,535 [1,2,4,15]
17 131,071* [2,16]
18 262,143 [6,17]
19 524,287* [0,1,4,18]
20 1,048,575 [2,19]
21 2,097,151 [1,20]
22 4,194,303 [0,21]
23 8,388,607 [4,22]
24 16,777,215 [0,2,3,23]
25 33,554,431 [7,24]
26 67,108,863 [0,1,5,25]
27 134,217,727 [0,1,4,26]
28 268,435,455 [2,27]
29 536,870,911 [1,28]
30 1,073,741,823 [0,3,5,29]
31 2,147,483,647* [2,30]
32 4,294,967,295 [1,5,6,31]
* Sequences whose length is a prime number
Be aware that there are multiple solutions for tap positions to generate maximum length sequences.
There is one major issue with using LFSRs: if all stages happen to be '0', the shift register gets "stuck". This is because the XOR of all '0's is still '0'. The XOR feedback does not produce a '1' to get the sequence started again. To prevent this condition, the routine must be first loaded with a non-zero seed value. This value can be any number at all, as long as it is not zero. The numbers generated by the LFSR are based on the seed value. You will get the same sequence of numbers, over and over, unless at some point the LSFR is reloaded with a different seed.
Where does this seed value come from? It will depend on what is available in your particular application. For example, if your system has access to a RTC (real-time clock), then a good seed is based off the time. You can read the current time and/or date, mask off portions and use that as a seed. Another example is temperature. If your system can read temperature (assuming it's not constant) then that can make a good seed. The ADC of the MAX765x can be set to read all sorts of things: scales AC power line voltage, some sensor position or even amplified Johnson noise from a Zener diode (a common practice in cryptography).
However, in some cases you will just have to use 01H or some other number, and accept the fact that the sequence will repeat eventually and in a predetermined pattern.
The routine presented uses a 25-bit sequence, which repeats after being called 33 million times. Even if you cannot produce a unique seed each time, the length is such that in most applications, the "randomness" is more than sufficient.
The MAX765x listing is shown below. The routine uses four 8-bit memory locations labeled RN1-RN4. The lower 3 bytes RN1-RN3 are used for 24 bits, and the MSB of RN4 is the 25th bit. The algorithm uses XOR feedback (using the processor's XRL instruction) from "stages" 25 (the Carry bit) and stage 7 (the MSB of RN1). Since all of the resisters are simply RAM locations, you can form up to 32-bit wide random numbers. For this example, an 8-bit number RANNUM is stored in RAM at the end of the routine.
To get a true Gaussian distribution function of the random numbers, you can do further processing. Adding some arbitrary number of consecutive samples and taking the average (say 4) will create a Gaussian distribution.
One programming 'trick' which is used in the algorithm are "byte swaps" to simulate a "shifting by 8 clocks". This is to save CPU clock cycles. For example, if the original byte order was ABCD, after the byte-swaps the order is BCDA. This prevents the code from having to do "housekeeping" from shifting a byte's MSB into the next byte's LSB. It doesn't matter if the random numbers are calculated every clock or every 8 clocks: they are still random. Since the total length of the LFSR is a product of 3 prime numbers (31, 601 and 1801) the sequence is still 33,554,431 subroutine calls until the sequence repeats! Of course, since we are looking at 8 of the bits for our example, the values are restricted to 00H to 0FFH, and so the same value will be returned multiple times.
Another cycle-saving 'trick' used is when the XOR of the 2 bits of interest is executed, the entire contents of RN1 is altered (see the comment below).
;
; SUBROUTINE RANDOM
;
; GENERATES RANDOM NUMBERS USING 25 BIT SHIFT REGISTER
; WITH XOR FEEDBACK ON STAGES 7 AND 25 (MAX CYCLE LENGTH)
;
; IN ORDER FOR THIS ROUTINE TO WORK, THERE ARE 2 THINGS TO CONSIDER:
; A) SOME TYPE OF NON-ZERO VALUE ‘SEED’ MUST FIRST BE LOADED INTO RN1
: B) THE SEQUENCE WILL REPEAT AFTER APPROX 33 MILLION CALLS TO THE ROUTINE
;
; CPU RESOURCES REQUIRED:
;
; 6 RAM LOCATIONS AS FOLLOWS
;
; RANNUM: THE CALCULATED RANDOM NUMBER
; RN1-RN1: FORMS THE SHIFT REGISTER
; TEMP1: A TEMPORARY SCRATCH-PAD REGISTER
;
; THE ROUTINE DESTROYS THE A REGISTER AND THE CARRY BIT
;
;
RANDOM: MOV A,RN4 ; BIT 25 TO CARRY
RRC A
MOV RN4,RN3
MOV RN3,RN2
MOV RN2,RN1 ; SHIFT ALL BYTES LEFT
MOV A,RN4 ; WAS RN3
RRC A ; GET BIT 25 (IN CARRY) INTO OLD RN3
MOV TEMP1,A ; SAVE IT FOR LATER
MOV A,RN1
RLC A ; BIT 1 TO 7 IN POSITION
MOV RN1,A ; PUT BACK
MOV A,TEMP1 ; RESTORE A
XRL A,RN1 ; MOD 2 SUM OF ALL BITS IN RN1 AND THE CARRY BIT
MOV TEMP1,A ; SAVE IT
MOV A,RN4
RRC A
MOV RN4,A ; ROTATE RN4
MOV A,RN3
RRC A
MOV RN3,A ; ROTATE RN3
MOV A,RN2
RRC A
MOV RN2,A ; ROTATE RN2
MOV A,TEMP1 ; RESTORE A
RLC A
MOV RN1,A ; xor OVER-WRITES ALL 8 BITS, BUT DOESN’T MATTER
MOV RANNUM,A ; RANDOM NUMBER!!
RET
Related Parts APP 1743: Sep 25, 2002
MAX7651 Flash Programmable 12-Bit Integrated Data-Acquisition Systems Full Data Sheet
(PDF, 488kB)
MAX7652 Flash Programmable 12-Bit Integrated Data-Acquisition Systems Full Data Sheet
(PDF, 488kB)
Automatic Updates
Would you like to be automatically notified when new application notes are published in your areas of interest? Sign up for EE-Mail™.
Your Comments
Login or register to post a comment.
Applications such as spread-spectrum communications, security, encryption and modems require the generation of random numbers. The most common way to implement a random number generator is a Linear Feedback Shift Register (LFSR). Codes generated by a LFSR are actually "pseudo" random, because after some time the numbers repeat. The trick is to use a shift register of sufficient length so that the pattern repeats after some extremely long time.
A basic LFSR of length five is shown in Figure 1. The shift register is a series-connected group of flip-flops, with XOR feedback. An XOR gate is use to scramble the input bit.
Figure 1. 5-stage linear feedback shift register.
Figure 1. 5-stage linear feedback shift register.
There are tables that give the proper feedback tap position for generating sequences that take the maximum number of clocks to repeat. Such a table is shown below:
Table 1. Taps for Maximal-Length LFSRs with 2 to 32 Bits
No. of bits Length of Loop Taps
2 3* [0,1]
3 7* [0,2]
4 15 [0,3]
5 31* [1,4]
6 63 [0,5]
7 127* [0,6]
8 255 [1,2,3,7]
9 511 [3,8]
10 1023 [2,9]
11 2047 [1,10]
12 4095 [0,3,5,11]
13 8191* [0,2,3,12]
14 16,383 [0,2,4,13]
15 32,767 [0,14]
16 65,535 [1,2,4,15]
17 131,071* [2,16]
18 262,143 [6,17]
19 524,287* [0,1,4,18]
20 1,048,575 [2,19]
21 2,097,151 [1,20]
22 4,194,303 [0,21]
23 8,388,607 [4,22]
24 16,777,215 [0,2,3,23]
25 33,554,431 [7,24]
26 67,108,863 [0,1,5,25]
27 134,217,727 [0,1,4,26]
28 268,435,455 [2,27]
29 536,870,911 [1,28]
30 1,073,741,823 [0,3,5,29]
31 2,147,483,647* [2,30]
32 4,294,967,295 [1,5,6,31]
* Sequences whose length is a prime number
Be aware that there are multiple solutions for tap positions to generate maximum length sequences.
There is one major issue with using LFSRs: if all stages happen to be '0', the shift register gets "stuck". This is because the XOR of all '0's is still '0'. The XOR feedback does not produce a '1' to get the sequence started again. To prevent this condition, the routine must be first loaded with a non-zero seed value. This value can be any number at all, as long as it is not zero. The numbers generated by the LFSR are based on the seed value. You will get the same sequence of numbers, over and over, unless at some point the LSFR is reloaded with a different seed.
Where does this seed value come from? It will depend on what is available in your particular application. For example, if your system has access to a RTC (real-time clock), then a good seed is based off the time. You can read the current time and/or date, mask off portions and use that as a seed. Another example is temperature. If your system can read temperature (assuming it's not constant) then that can make a good seed. The ADC of the MAX765x can be set to read all sorts of things: scales AC power line voltage, some sensor position or even amplified Johnson noise from a Zener diode (a common practice in cryptography).
However, in some cases you will just have to use 01H or some other number, and accept the fact that the sequence will repeat eventually and in a predetermined pattern.
The routine presented uses a 25-bit sequence, which repeats after being called 33 million times. Even if you cannot produce a unique seed each time, the length is such that in most applications, the "randomness" is more than sufficient.
The MAX765x listing is shown below. The routine uses four 8-bit memory locations labeled RN1-RN4. The lower 3 bytes RN1-RN3 are used for 24 bits, and the MSB of RN4 is the 25th bit. The algorithm uses XOR feedback (using the processor's XRL instruction) from "stages" 25 (the Carry bit) and stage 7 (the MSB of RN1). Since all of the resisters are simply RAM locations, you can form up to 32-bit wide random numbers. For this example, an 8-bit number RANNUM is stored in RAM at the end of the routine.
To get a true Gaussian distribution function of the random numbers, you can do further processing. Adding some arbitrary number of consecutive samples and taking the average (say 4) will create a Gaussian distribution.
One programming 'trick' which is used in the algorithm are "byte swaps" to simulate a "shifting by 8 clocks". This is to save CPU clock cycles. For example, if the original byte order was ABCD, after the byte-swaps the order is BCDA. This prevents the code from having to do "housekeeping" from shifting a byte's MSB into the next byte's LSB. It doesn't matter if the random numbers are calculated every clock or every 8 clocks: they are still random. Since the total length of the LFSR is a product of 3 prime numbers (31, 601 and 1801) the sequence is still 33,554,431 subroutine calls until the sequence repeats! Of course, since we are looking at 8 of the bits for our example, the values are restricted to 00H to 0FFH, and so the same value will be returned multiple times.
Another cycle-saving 'trick' used is when the XOR of the 2 bits of interest is executed, the entire contents of RN1 is altered (see the comment below).
;
; SUBROUTINE RANDOM
;
; GENERATES RANDOM NUMBERS USING 25 BIT SHIFT REGISTER
; WITH XOR FEEDBACK ON STAGES 7 AND 25 (MAX CYCLE LENGTH)
;
; IN ORDER FOR THIS ROUTINE TO WORK, THERE ARE 2 THINGS TO CONSIDER:
; A) SOME TYPE OF NON-ZERO VALUE ‘SEED’ MUST FIRST BE LOADED INTO RN1
: B) THE SEQUENCE WILL REPEAT AFTER APPROX 33 MILLION CALLS TO THE ROUTINE
;
; CPU RESOURCES REQUIRED:
;
; 6 RAM LOCATIONS AS FOLLOWS
;
; RANNUM: THE CALCULATED RANDOM NUMBER
; RN1-RN1: FORMS THE SHIFT REGISTER
; TEMP1: A TEMPORARY SCRATCH-PAD REGISTER
;
; THE ROUTINE DESTROYS THE A REGISTER AND THE CARRY BIT
;
;
RANDOM: MOV A,RN4 ; BIT 25 TO CARRY
RRC A
MOV RN4,RN3
MOV RN3,RN2
MOV RN2,RN1 ; SHIFT ALL BYTES LEFT
MOV A,RN4 ; WAS RN3
RRC A ; GET BIT 25 (IN CARRY) INTO OLD RN3
MOV TEMP1,A ; SAVE IT FOR LATER
MOV A,RN1
RLC A ; BIT 1 TO 7 IN POSITION
MOV RN1,A ; PUT BACK
MOV A,TEMP1 ; RESTORE A
XRL A,RN1 ; MOD 2 SUM OF ALL BITS IN RN1 AND THE CARRY BIT
MOV TEMP1,A ; SAVE IT
MOV A,RN4
RRC A
MOV RN4,A ; ROTATE RN4
MOV A,RN3
RRC A
MOV RN3,A ; ROTATE RN3
MOV A,RN2
RRC A
MOV RN2,A ; ROTATE RN2
MOV A,TEMP1 ; RESTORE A
RLC A
MOV RN1,A ; xor OVER-WRITES ALL 8 BITS, BUT DOESN’T MATTER
MOV RANNUM,A ; RANDOM NUMBER!!
RET
Related Parts APP 1743: Sep 25, 2002
MAX7651 Flash Programmable 12-Bit Integrated Data-Acquisition Systems Full Data Sheet
(PDF, 488kB)
MAX7652 Flash Programmable 12-Bit Integrated Data-Acquisition Systems Full Data Sheet
(PDF, 488kB)
Automatic Updates
Would you like to be automatically notified when new application notes are published in your areas of interest? Sign up for EE-Mail™.
Your Comments
Login or register to post a comment.
发表评论
-
[转载]并发之痛 Thread,Goroutine,Actor
2017-04-06 19:21 595转自 http://jolestar.com/pa ... -
JVM动态调整字节码
2016-04-14 19:27 1233粗略的点开btrace的源码看了一下,实际上他只是封装了JD ... -
java字节码常量池处理说明
2016-04-13 23:23 11141. 根据java的字节码格式说明,常量池中每一项的大小不一 ... -
Mac OSX 10.10 Yosemite编译OpenJDK 8
2016-04-03 18:14 3508编译时间:2016-04-03 系统版本:Mac OS ... -
Java 并发之 ConcurrentSkipListMap 简述
2015-09-20 20:24 1125JCIP 提到了在 Java 6 中引入了两个新的并发集合类 ... -
hbase等源码导入eclipse流程
2015-09-20 19:00 1722hbase: 1. 下载源码 svn co ht ... -
最简单的平衡树(红-黑树)的实现
2015-09-04 08:04 1190在二叉搜索树(BST)的基础上,要实现一颗平衡树,可以使用 ... -
多线程程序中操作的原子性[转载]
2014-12-06 10:49 11680. 背景 原子操作就是不可再分的操作。在多线程程序中原子 ... -
6. 内存屏障[转载]
2014-11-26 00:07 716原文地址 作者:Martin Thompson 译者: ... -
5.合并写(write combining)[转载]
2014-11-25 21:54 735原文地址 译者:无叶 ... -
4. 内存访问模型的重要性[转载]
2014-11-25 21:53 1067在高性能的计算中,我 ... -
3. Java 7与伪共享的新仇旧恨[转载]
2014-11-25 21:45 882原文:False Shareing && J ... -
2. 伪共享(False Sharing)[转载]
2014-11-25 21:40 862作者:Martin Thompson 译者:丁一 缓存 ... -
lucene索引创建的理解思路
2014-06-29 23:12 1485虽然lucene4很早就出来,但是这里仍然以lucene3. ... -
lucene的拼写检查的实现原理
2014-06-08 18:19 13161. 建索引时, 使用ngram的方式创建索引 Sp ... -
字符串相似算法-(3) NGram Distance
2014-06-08 17:54 4903就是N-Gram version of edit dista ... -
字符串相似算法-(2) Levenshtein distance
2014-06-08 16:32 2231编辑距离概念描述: ... -
字符串相似算法-(1) Jaro-Winkler Distance
2014-06-08 12:05 6759Jaro-Winkler Distance 算法 ... -
tomcat参数编码处理过程
2014-06-07 09:49 18471. org.apache.coyote.http11 ... -
SSLEngine的示例
2014-05-26 19:44 7823为什么要使用SSLEngine, 参考javadoc的说明 ...
相关推荐
王教授的论文“2016-Pseudo-Random High-Frequency Square-Wave Voltage Injection”探讨了一种基于伪随机高频方波电压注入的无传感器控制技术,用于降低内转子永磁同步电机(IPMSM)驱动系统的可听噪声。...
是采用伪随机编码结构光照明主动视觉技术,用编码结构光照明被测场景,实现动态三维场景的重建
标题中的“Creat_pseudo-random Numbers_random_逆变法_伪随机数_stickdrq_python_”表明我们关注的是一个Python程序,它使用了逆变法来生成一系列的伪随机数。逆变法是一种通过数学变换将已知的随机序列转换为新...
标题“前端开源库-pseudo-elements”指向的是一个专门收集和整理CSS伪元素相关资源的开源项目,可能包含了一个详尽的伪元素列表,以及如何在实际项目中使用它们的示例和最佳实践。 描述中的“所有CSS伪元素的列表”...
随机数生成器(Random Number Generator, RNG)通常可以分为伪随机数生成器(Pseudo-Random Number Generator, PRNG)和真随机数生成器(True Random Number Generator, TRNG)。PRNG基于数学算法,通过一个初始种子...
Based on pseudo-likelihood, it applies soft expectation-maximization (EM) for good model fitting and hard EM for robust depth estimation. We introduce novel pixel difference models to enable such ...
MATLAB实现伪距单点定位_MATLAB_to_achieve_pseudo-distance_s_-Pseudo---distance-single-point-positioning
本篇文章将深入探讨"End-to-end Pseudo-LiDAR for Image-Based 3D Object Detection"这一主题,以及如何通过伪LiDAR技术实现视觉与LiDAR的高效融合。 首先,我们要理解什么是伪LiDAR。传统的LiDAR系统能够提供高...
在Python生态系统中,有许多开源库可供选择,其中之一就是"pseudo-python"。这个库的版本为0.2.12,它被打包成一个名为"pseudo-python-0.2.12.tar.gz"的压缩文件。该文件格式通常是Linux和Unix系统中常见的tarball,...
"has-pseudo-class"就是一个专注于处理CSS伪类的前端开源库。这个库的核心功能是检测一个CSS选择器是否包含有伪类,这对于理解和优化CSS选择器的使用,以及在动态渲染时避免不必要的计算,有着重要的意义。 伪类是...
伪随机数生成器(Pseudo-Random Number Generator, PRNG)是一类算法,用于生成一系列数字,这些数字在统计上具有随机性特征,但实际上是由确定性的算法产生的。一个好的PRNG应该满足以下条件: 1. **均匀性**:生成...
This book provides a comprehensive, up-to-date description of the methodologies and the application ... and pseudo-random sequence generation for secure authentication and for stream cipher cryptology.
在IT领域,伪随机数生成器(Pseudo-Random Number Generator, PRNG)是一个至关重要的工具,广泛应用于各种计算任务,如加密、模拟、游戏、图形渲染等。标题中的"PSEUDO_RANDOM_ise9migration.zip_pseudo random_...
The function is used to generate a pseudo-random code generation of any GPS satellite 37 C / A codes Sv_id - satellite number cod - a vector comprising an output sequence g2s - vector containing the ...
We propose and demonstrate a scheme to measure the distribution of temperature along an optical fiber based on pseudo-random sequence modulation. In our experimental work, current modulation with a ...
这个压缩包“前端开源库-pseudo-elements.zip”可能包含了一些关于`pseudo-elements`的示例、教程或工具,旨在帮助开发者更深入地理解和运用这个技术。 `pseudo-elements`主要有以下几种: 1. `::before`: 这个伪...
伪随机数生成器(Pseudo-Random Number Generators, PRNGs)是计算机科学中一个重要的概念,特别是在模拟、加密、游戏开发以及各种统计计算中。C 语言因其高效和跨平台特性,常被用于实现这类算法。本主题将深入探讨...