228 CHAPTER 10 BATTERIES INCLUDED random The (Web design rates)
228 CHAPTER 10 BATTERIES INCLUDED random The random module contains functions that return random numbers, which can be useful for simulations or any program that generates random output. Note Actually, the numbers generated are pseudo-random. That means that while they appear completely random, there is a predictable system that underlies them. However, because the module is so good at pretending to be random, you probably won t ever have to worry about this (unless you want to use these numbers for strong-cryptography purposes, in which case they may not be strong enough to withstand determined attack but if you re into strong cryptography, you surely don t need me to explain such elementary issues). If you need real randomness, you should check out the urandomfunction of the os module. The class SystemRandom in the random module is based on the same kind of functionality, and gives you data that is close to real randomness. Some important functions in this module are shown in Table 10-7. Table 10-7. Some Important Functions in the random Module Function Description random() Returns a random real number n such that 0 =n < 1 getrandbits(n) Returns n random bits, in the form of a long integer uniform(a, b) Returns a random real number n such that a =n < b randrange([start], stop, [step]) Returns a random number from range(start, stop, step) choice(seq) Returns a random element from the sequence seq shuffle(seq[, random]) Shuffles the sequence seq in place sample(seq, n) Chooses n random, unique elements from the sequence seq The function random.randomis one of the most basic random functions; it simply returns a pseudo-random number n such that 0 < n < 1. Unless this is exactly what you need, you should probably use one of the other functions, which offer extra functionality. The function random.getrandbits returns a given number of bits (binary digits), in the form of a long integer. This is probably mostly useful if you re really into random stuff (for example, working with cryptography). The function random.uniform, when supplied with two numerical parameters a and b, returns a random (uniformly distributed) real number n such that a < n < b. So, for example, if you want a random angle, you could use uniform(0,360). The function random.randrange is the standard function for generating a random integer in the range you would get by calling rangewith the same arguments. For example, to get a
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.