Random Pi Digits Generator

  • Share this:

Code introduction


Generate a random sequence of digits from the number pi with a specified length


Technology Stack : random, math

Code Type : Calculation function

Code Difficulty : Intermediate


                
                    
def random_pi_digits(num_digits):
    from random import random
    from math import sqrt, pi

    digits = []
    for _ in range(num_digits):
        digit = round(random() * 10)
        digits.append(str(digit))
    return ''.join(digits)                
              
Tags: