+ 1
How to generate a random 10 digit integer?
Instead of using import random and random.randint(1111111111, 9999999999) which does NOT really work, I want each digit to have a chance of being 0-9 instead of it being in counting form? I haven't coded in around a year so it's hard to remember this type of thing.
9 ответов
+ 7
Xmosity try something like this however I set minimum value as 1 not 0 and used time as seed.
no import of random or use of randint
https://sololearn.com/compiler-playground/cM7F34IXD93F/?ref=app
+ 3
I'm not sure why you say that doesn't work. That's mostly correct, except the first number should be 1000000000.
Here's working code:
import random
for i in range(0,100):
x = random.randint(1_000_000_000, 9_999_999_999)
print(x)
+ 2
You're welcome Xmosity
+ 2
----> Import Error: Ensure the random module is correctly imported.
----> Leading Zeros: The number might not keep leading zeros if converted to an integer.
Here my code playground check 👀:
https://www.sololearn.com/en/compiler-playground/cK53nGWnO2m3
+ 2
Xmosity ,
i tried sticking on your idea of creating digits and combine them to an integer number.
the code does not use strings to do this, it just uses numerical methods. it also has the flexibility what the first digit should be, and also about the number of digits the final number should have.
https://sololearn.com/compiler-playground/c6J13t8K94cE/?ref=app
+ 1
I want each number to have a probability of zero, putting 1000... would make the first number a minimum of 1 and would make it not as random.
+ 1
thanks
0
Calculate Your BMR in python