Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,788 questions

51,694 answers

573 users

How to generate random floating point numbers with seed() function for initializing the pseudorandom generator in Python

4 Answers

0 votes
import random

random.seed(5)

for i in range(10):
    print('%04.3f' % random.random())

'''
run:

0.623
0.742
0.795
0.942
0.740
0.922
0.029
0.466
0.943
0.649

'''

 



answered Apr 6, 2016 by avibootz
0 votes
import random

''' use system time to generate next random number '''
random.seed()

for i in range(10):
    print('%04.3f' % random.random())

'''
run:

0.493
0.173
0.768
0.592
0.174
0.293
0.947
0.921
0.588
0.853

'''

 



answered Apr 6, 2016 by avibootz
0 votes
import random

''' generate the same random number '''
random.seed(5)
print('%04.3f' % random.random())

random.seed(5)
print('%04.3f' % random.random())

random.seed(5)
print('%04.3f' % random.random())


'''
run:

0.623
0.623
0.623

'''

 



answered Apr 6, 2016 by avibootz
0 votes
import random

''' generate different random number '''
random.seed()
print('%04.3f' % random.random())

random.seed()
print('%04.3f' % random.random())

random.seed()
print('%04.3f' % random.random())


'''
run:

0.660
0.774
0.058

'''

 



answered Apr 6, 2016 by avibootz
...