随机数

随机数

# 环境变量
# import os,sys
# base = os.path.abspath('..')
# sys.path.insert(0,base)

# 忽略警告信息
# import warnings
# warnings.simplefilter(action = "ignore", category = FutureWarning)
# warnings.filterwarnings("ignore")

# 内置
# import os
# import sys
# import time
import random
# import re
# import itertools
import math
# import shutil

# 数据处理
# import pandas as pd  
import numpy as np  
# from pandas.tseries.offsets import DateOffset
# import openpyxl

# 爬虫
# import requests
# import urllib
# from selenium import webdriver
# from lxml import etree
# from bs4 import BeautifulSoup
# import json

# 进程
# import threadpool
# import threading

# 数据库
# import cx_Oracle
# from sqlalchemy import create_engine



if __name__ == '__main__':
    # 随机数字
    r1 = random.random()
    print('随机实数:',r1)

    r2 = random.choice('aerfasdf')
    print('指定值随机数:',r2)

    r3 = random.randrange(1,10,1)
    print('范围随机整数:',r3)

    r4 = random.uniform(4,7)
    print('范围随机实数:',r4)


    # 随机序列
    r6 = range(12)
    print('随机列表:',r6)

    r7 = np.arange(12)
    print('随机数组:',r7)


    # 随机矩阵
    r8 = np.arange(12).reshape(3,4) # -1时自动
    print('随机整数矩阵1:\n',r8)

    r9 = np.random.randint(12,size=(3,4))
    print('随机整数矩阵2:',r9)

    r10 = np.random.rand(3,4) # = np.random.sample((3,4)) = np.random.random((3,4)) = np.random.ranf((3,4))
    print('随机实数矩阵,[0-1):\n',r10)

    r11 = np.random.randn(3,4) 
    print('标准正态分布:\n',r11)

    r12 = np.random.choice(range(10),3,replace=False)
    print('指定值随机数组:',r12)

    r13 = np.random.bytes(10)
    print('随机字节:',r13)


    # 随机种子
    random.seed('种子',1)
    print('种子随机数:',random.random())
    random.seed('种子',1)
    print('种子随机数:',random.random())

    np.random.seed(10)
    print('种子随机矩阵:\n',np.random.rand(3,4))
    np.random.seed(10)
    print('种子随机矩阵:\n',np.random.rand(3,4))


    # 洗牌
    r14 = list(range(10))
    random.shuffle(r14)
    print('列表洗牌:',r14)

    r15 = np.arange(12).reshape(3,4)
    np.random.shuffle(r15)
    print('矩阵洗牌:\n',r15)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值