which can be used for writing non-blocking network code. The third-party Twisted library is a popular and feature- rich alternative. 

## 4.6 Databases 

## 4.6.1 Are there any interfaces to database packages in Python? 

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. 

## 4.6.2 How do you implement persistent objects in Python? 

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. 

## 4.7 Mathematics and Numerics 

## 4.7.1 How do I generate random numbers in Python? 

The standard module$_{random}$implements a random number generator. Usage is simple: 

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: 

• randrange(a, b) chooses an integer in the range [a, b). 

• uniform(a, b) chooses a floating point number in the range [a, b). 

• normalvariate(mean, sdev) samples the normal (Gaussian) distribution. 

Some higher-level functions operate on sequences directly, such as: 

• choice(S) chooses a random element from a given sequence. 

• shuffle(L) shuffles a list in-place, i.e. permutes it randomly. 

There’s also a$_{Random}$class you can instantiate to create independent multiple random number generators. 

