# Neden randint() rastgele değil?

2020-02-18'de Mahir Yıldızhan paylaştı.

Ben, bilgisayarlar ve arkada çalışan kodları merak eden birisiyim. I like to confirm the known truths. Most of time, I confirm they are true. But this time, It’s seems like one known truth is wrong. This article will be related to this one. I have been using Python for 2 years. And I used several Python libraries. “Random” library is one of the most useful ones. I heard from somewhere (I can’t remember exact source) that If I use randint function I’ll get random numbers. And if I increase the amount of generation I should get very close amount of numbers which I generate. I prepared a basic algorithm on Google Colab which can generate “n” times numbers from 1 to 10 and display percentage of them. Also I use “seaborn” to visualise it. Here is the codes and results. Importing libraries:
# Import the necessary libraries
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import random
Creating a function to repeat calculations:
# Create a function to repeat process
def PrintPercentage(x):
Array =  * 10
for a in range(0,x):
r = random.randint(0, 10)
Array[r-1] +=1
print(“After “+str(x)+” times generation, percentages:”)
print(“ 1: %”+str(round(Array/x*100,2)))
print(“ 2: %”+str(round(Array/x*100,2)))
print(“ 3: %”+str(round(Array/x*100,2)))
print(“ 4: %”+str(round(Array/x*100,2)))
print(“ 5: %”+str(round(Array/x*100,2)))
print(“ 6: %”+str(round(Array/x*100,2)))
print(“ 7: %”+str(round(Array/x*100,2)))
print(“ 8: %”+str(round(Array/x*100,2)))
print(“ 9: %”+str(round(Array/x*100,2)))
print(“10: %”+str(round(Array/x*100,2)))
x = [1,2,3,4,5,6,7,8,9,10]
y = Array
data = pd.DataFrame(data={‘Number’: x, ‘Percentage’: y})
grid = sns.lmplot(‘Number’, ‘Percentage’, data, height=7, truncate=True, scatter_kws={“s”: 100})
plt.show()
randint() fonksiyonunu 1'den 100 milyon keze kadar sayı ürettirme:
PrintPercentage(1)
PrintPercentage(10)
PrintPercentage(100)
PrintPercentage(1000)
PrintPercentage(10000)
PrintPercentage(100000)
PrintPercentage(1000000)
PrintPercentage(10000000)
PrintPercentage(100000000)