Adventurer #13
31 марта 2002 |
|
Exchange of experience - an unscientific Algorithm for Random Number (RND).
(C) Research / Volgasoft Scientific RND In my esteemed journal Spectrum Expert were laid out at least all the materials for self-writing wire, and even the cast wire engine ELITE. Now we learn how to generate pseudo-random numbers, and thus learn to write everything that happens inside the station (map of the galaxy and the names of the planets for example:). Enough will scrape a modest materialchik on likeness of artificial intelligence, and anyone can write the elite for two months: Main methods of generating random There are two numbers (and finally can - one): 1) the shift of floating point numbers (Sometimes with the admixture of shifted copies); 2) Papal method:) Tyk Now, consider the Pope's method: N [i +1] = mod (A * N [i], Z); - where mod = Modulo In other words: the next number = remainder of division of some constants A, multiplied by the previous number and the constant Z. That's it! On the finger assembly: constA EQU 137 ; Z EQU 8 N EQU 3; seed LD IX, array; array address LD (IX), N LD DE, constA; constant A LD B, 32; how many numbers to generate LL1 LD L, (IX) LD H, 0 PUSH DE CALL MUL_HL_DE; "A * N [i]" POP DE LD (IX +1), L; remainder of the division by 256, also known as the low byte INC IX DJNZ LL1 ; Ready The range of values generated numbers depends on the constants. In the example, Z = 256, A = 137. The values of Z - choose to taste (Actually, in this example would not hurt beginning to shift the result of multiplying right by one bit, and then take the remainder). The values of A are chosen so that the distribution was close to uniform. Usually takennumber (I forgot how their school was named - which are divided into themselves and one) such as 5, 7.13, 17, 19, 23, etc. Make sure that there was no zeros, otherwise the generator will rise. As I have said that numbers were obtained not only odd or even - to play with the translations. To generate numbers not only arranged in a specified number of bits (8 - 1 .. 255, 7 - 1 .. 127) will have to ruin a few numbers, or use multiple generators, for example the numbers 1 .. 191: LD A, n1 AND A, 1963 LD C, A LD A, n2 AND A, 127 ADD A, C LD (RESULT), A But how to generate the names of the planets in the elite - everyone knows - we take, we make an array of syllables (two letters) and we start the generator - one number corresponds to one syllable, and rolls the two-letter planet, four, six: By the way, like algorithm is used in calculating the checksum, the including at the same VG93. Well that's all: How to tell you about the current AI (or someone will tell in the pages Adventurer 'a) from you with each of the elite :))).
Other articles:
Similar articles:
В этот день... 21 November