Home  >  Article  >  Backend Development  >  Python method to generate random numbers with any range and any precision

Python method to generate random numbers with any range and any precision

不言
不言Original
2018-04-09 15:00:303811browse

The following is a Python method for generating random numbers with any range and any precision. It has certain reference value and I hope it will be helpful to everyone.

An example is as follows:

# -*- coding: utf-8 -*-
import numpy as np
random = np.random.RandomState(0)#RandomState生成随机数种子
for i in range(200):#随机数个数
 a = random.uniform(-0.1, 0.1)#随机数范围
 print round(a, 2)#随机数精度要求


The above is the detailed content of Python method to generate random numbers with any range and any precision. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn