Tham khảo tài liệu 'testing computer software phần 6', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | RNG functions on large systems Knuth 1981 and microcomputers are often poor. The worst don t even use the basic algorithm correctly they use floating point routines to do what should be strictly integer arithmetic. Others only work with numbers between 0 and 65 535 and repeat their sequence every 65 536th number. These are unacceptable. We can t go into the subtleties of creating and testing RNGs in this book. Kaner Vokey 1984 overview the problems and testing techniques. Knuth 1981 is the authoritative text. Here are some suggestions Read up on random number generators before you do any testing using random inputs. Don t trust someone else s generator just because it s there even if it s provided as part of a respectable language on a respectable machine. Keep reading about generators until you understand the suggestions that follow. You don t have to take the suggestions but if you don t understand them you know little enough that you risk wasting lots of time generating oops-they-weren t-so-random-test cases. Figure Parameters of some published random number generators M A c 2 32 69069 odd number 2 32 1664525 odd number 2 35 17059465 odd number 2 40 27182819621 3 2 40 8413453205 99991 2 31167285 odd number 2 636413622384679300 odd number R N 1 A R N C modulo M If you re going to use a generator supplied with your programming language sample many 100-tOGQ numbers from it and shuffle them. That is use fur ther random numbers to reorder them. This is slow but it brings many poor RNGs up to a level of acceptability. If you use a language that allows high precision integer not floating point arithmetic consider writing your own function to use one of the follow ing generators. Define the RNG by R N 1 A R N C modulo M That is generate the N 1 st number by multiplying the Nth by A adding C and taking the result modulo M. The larger M is the better but slower. Figure lists good values for the parameters. The value of C is not critical as long as it s odd but .