Python Frequently Asked Questions, Release 3.9.5 4.6 Databases 4.6.1 Are there any interfaces to database packages in Python? 4.6.2 How do you implement persistent objects in Python? 4.7 Mathematics and Numerics 4.7.1 How do I generate random numbers in Python? import random random.random() This returns a random floating point number in the range [0, 1). There are also many other specialized generators in this module, such as: Some higher-level functions operate on sequences directly, such as: The standard module$_{random}$implements a random number generator. Usage is simple: Yes. Interfaces to disk-based hashes such as DBM and GDBM are also included with standard Python. There is also the sqlite3 module, which provides a lightweight disk-based relational database. Support for most relational databases is available. See the DatabaseProgramming wiki page for details. which can be used for writing non-blocking network code. The third-party Twisted library is a popular and feature- rich alternative. The$_{pickle}$library module solves this in a very general way (though you still can’t store things like open files, sockets or windows), and the$_{shelve}$library module uses pickle and (g)dbm to create persistent mappings containing arbitrary Python objects. There’s also a$_{Random}$class you can instantiate to create independent multiple random number generators. Chapter 4. Library and Extension FAQ 58 • shuffle(L) shuffles a list in-place, i.e. permutes it randomly. • choice(S) chooses a random element from a given sequence. • normalvariate(mean, sdev) samples the normal (Gaussian) distribution. • uniform(a, b) chooses a floating point number in the range [a, b). • randrange(a, b) chooses an integer in the range [a, b).