+ 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.

14th Sep 2024, 10:02 PM
Xmosity
9 Respuestas
+ 6
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
15th Sep 2024, 12:27 AM
BroFar
BroFar - avatar
+ 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)
15th Sep 2024, 12:16 AM
Jerry Hobby
Jerry Hobby - avatar
+ 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
15th Sep 2024, 8:04 AM
Muhammad Nouman Ali
Muhammad Nouman Ali - avatar
+ 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
15th Sep 2024, 9:39 AM
Lothar
Lothar - avatar
+ 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.
15th Sep 2024, 12:21 AM
Xmosity
+ 1
thanks
15th Sep 2024, 1:07 AM
Xmosity
+ 1
You're welcome Xmosity
15th Sep 2024, 1:40 AM
BroFar
BroFar - avatar
0
Calculate Your BMR in python
16th Sep 2024, 7:02 PM
Rozi Roti
Rozi Roti - avatar