Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- decimal.Decimal(random.randrange(10000))/100
- >>> import random, decimal
- >>> decimal.Decimal(str(random.random()))
- Decimal('0.467474014342')
- >>> import decimal
- >>> import random
- >>> def gen_random_decimal(i,d):
- ... return decimal.Decimal('%d.%d' % (random.randint(0,i),random.randint(0,d)))
- ...
- >>> gen_random_decimal(9999,999999) #4 digits before, 6 after
- Decimal('4262.786648')
- >>> gen_random_decimal(9999,999999)
- Decimal('8623.79391')
- >>> gen_random_decimal(9999,999999)
- Decimal('7706.492775')
- >>> gen_random_decimal(99999999999,999999999999) #11 digits before, 12 after
- Decimal('35018421976.794013996282')
- >>>
- from random import random
- from decimal import Decimal
- randdecimal = lambda: Decimal("%f" % random.random())
Add Comment
Please, Sign In to add comment