+ 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
8 Answers
+ 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
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
You're welcome Xmosity
15th Sep 2024, 1:40 AM
BroFar
BroFar - 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
0
Calculate Your BMR in python
16th Sep 2024, 7:02 PM
Rozi Roti
Rozi Roti - avatar