VC learning materials collection (20): Random number (repost)

xiaoxiao2021-03-06  44

A well-written PRNG can create a sequence, and this sequence is the same as the properties of many of the sequences of the true random number. For example: PRNG can generate any numbers within one range with the same chance. PRNG can generate a stream with any statistical distribution. The digital stream generated by the PRNG does not have an identifiable mode. The PRNG cannot do is unpredictable. This sequence can be easily estimated if you know the seeds and algorithms. The random number generated by the computer is generally only a long period of series, not true random number. That is, the random number is generally a pseudo-random number, and each random number is a set number (period of cycle) starting by the random seed. Generally, in order to randomly, the random seed is usually generated in the system. Take a look at the example below, from it, readers should be able to experience it.

Main () {INT i; scand (time (null)); / * can read its clock value to the computer, and automatically set the value to the random number * / for (i = 0; i <10; i ) { Printf ("% 10D", 1 (RAND ()% 6)); / * Here 1 is the moving value, he is equal to the first number of the range of continuous integers * /} / * (B is the proportional factor He * / return (0); / * equal to the range width of the desired continuous integer value; * /} From mathematics, in order to get a periodic and longer random sequence, we can use the following method: (this is I saw it in a book. Everyone can check it, I can't remember it, huh) float rand (long * idum) {Int J; long k; static long = 0; static long IV [NTAB]; FLOAT TEMP; if (* idum <= 0 ||! iy) {i (* idum) <1) * idum = 1; else * idum = - (* idum); for (j = NTAB 7; j> = 0; j -) {k = (* idum) / q; * idum = IA * (* idum-k * iq) -k * ire; if (* idum <0) * idum = Im; if (j RNMX Return float (RNMX); Else Return Temp;} [Note:] Some articles, according to the working principle of Randomize, use the function Timer to get the second to the midnight Number, and then "" attenuate "processing according to the random value size to be obtained, the value obtained, which can be called the true random value, I think this is also a human method, still has it Deterministic and periodicity, still not be true random number, simply changing the generation logic calculation method of the pseudo-random number does not achieve the purpose, the most effective way can only change the rand_seed, which is the seed. Moreover, the changed rand_seed should not be artificial. (Note: Currently, a random number generator associated with the CPU temperature is built in the Intel's PIII processor, which is a relatively effective seed generator.) Better approach is based on the "random event" to generate random numbers, such as Keyboard and mouse input value, interrupt, disk read, and more.

However, many servers do not have keyboards and mice, many "black box" products do not have a hard drive, so it is difficult to find a good random number, of course, the communication key is the same. For example, if the network status, the random number is "random". Electrical noise and sound frequencies may be a good random number, but most people are afraid that they are not willing to add such devices in their computer, and may also have problems such as equipment failure and external manipulation (influence). It is a problem that must be considered for a gateway server to handle a large amount of connection. If you can pass, accurately detect the energization current intensity of the machine CPU, as a random number, or some other unintended interference, and the instantaneous change is quick to obtain seeds, it will enable the random number of compatants and requirements. three. Several random number of acquisitions 1. Generate a random number in a range, we can use J = 1 (int) (n * rand () / (rand_max 1.0)) to generate a 0 to n random number. If INT x = rand ()% 100; the random number of random numbers between 0 and 100 is not desirable, the preferred approach is: j = (int) (100.0 * rand () / (Rand_MAX 1.0))), of course, we can also use Random (100). The following example is used with random (n) .2, the number of random randoms is desired to take 0-99, but cannot be 6. Workaround: x = random (100); while (x == 6) {x = random (100);} If you want to take 0-99 random number, don't 5 multiple solutions: x = random (100 WHILE ((x% 5) == 0) {x = random (100);} 3, with a random number from a continuous range. The random number is taken within the range of 40-50. Workaround: x = random (11) 404, take the randancy from a group of chaos. Such as: from 67, 87, 34, 78, 12, 5, 9, 108, 999, and 378 ten numbers. Workaround: You can store some ten numbers with an array, and then random number to be taken in 0-9 as the serial number, and the random number is achieved. A = New Array (67, 87, 34, 78, 12, 5, 9, 108, 999, 378); j = random (10); x = a [j]; four. Generate random numbers with a certain distribution on this point, there is an article well written, see: non-uniform distribution of random numbers and its application in the simulation study computer: Hu present Liu Xiangming Fang Chi dry Unit: Hu present (Hubei workers Medical Hospital Jingzhou 434000); Liu Xiangming (Jingzhou 434000, Hubei Workers Medical College is now doctoral student of China University of Science and Technology); Square Dry (Hubei Workers Medical College Jingzhou 434000 Zhongshan Medical University) Key words: non-uniform distribution random number; computer simulation; Design Summary: Non-uniform distributed random number is an important role in conducting computer simulation research, but computer high-level languages ​​typically only provide functions that produce uniform distribution random numbers, bringing difficulties to research work. The method proposed in this paper solves this problem, and has strong applicability.

Category Number: O 242.1 Article Number: 1004-4337 (2000) 01-0059-02 ▲ 1 The Common Computer Advanced Program Design Language, Most of the Computer Advanced Programming Languages, Most of the production of continuously distributed in the [0, 1] interval Independent random number R function. If the resulting random number is simple to transform X = A (B-a) R, the random number X which is evenly distributed across the interval [a, b] can be obtained. If the combination with the fetch or rounding function, the discrete evenly distributed random number is also available, which provides convenient to computer simulation. However, in many cases computer simulation requires use of non-uniform random numbers in certain specific regular distributions. For example, in the simulation study of the ion channel gating model, it is often used to obey the non-uniform distribution of non-uniform distributions such as index distribution, logarithmic distribution, normal distribution, and P. pine distribution. At this point, a function or process can be prepared in the source program. In recent years, the computer simulation research work [1, 2], a large number of discounted random numbers were used, and successful. Since the discrete random number can be converted by a continuous random number by a route of approach or rounding, this paper focuses on the principle and application examples of the non-uniform distribution of continuous random numbers, and gives the class PASCAL language [3] The corresponding functions and procedures. People who have mastered any computer advanced language programming technology and data structure knowledge can easily convert the procedures that can be run, and have a lot of flexibility and strong practicality. 2 Generating principle assumes that the continuous random variable X is a function x = (r) (1) of continuous random variable R, which is known from the probability statistical knowledge, X and R should be equal to the value of the distribution function of the corresponding point, that is, R's inverse transform f (x) = f (r) (2) where R is (1) solution, ie R = -1 (x) = ψ (x) in special case, if R is in the [0, 1] interval The continuous random variable in the inner distribution, then the probability P (r 0.

转载请注明原文地址:https://www.9cbs.com/read-75496.html

New Post(0)