# Random Number


```python
import numpy as np
import matplotlib.pyplot as plt 
```

    c:\Users\leona\anaconda3\lib\site-packages\numpy\_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs:
    c:\Users\leona\anaconda3\lib\site-packages\numpy\.libs\libopenblas.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll
    c:\Users\leona\anaconda3\lib\site-packages\numpy\.libs\libopenblas.XWYDX2IKJW2NMTWSFYNGFUWKQU3LYTCZ.gfortran-win_amd64.dll
      warnings.warn("loaded more than 1 DLL from .libs:"



```python
np.random.rand(1)
```




    array([0.30236111])




```python
np.random.randint(low = 1, high = 10)
```




    9




```python
n = 1000000
x = np.random.rand(n)
y = np.random.rand(n)
r = np.sqrt(x**2+y**2)
inside = 0
outside = 0
for i in range(len(r)):
    if r[i] <= 1 :
        inside += 1
inside 
```




    784948




```python
r
```




    array([0.60574234, 0.93723258, 0.9383093 , ..., 0.60240754, 0.39812025,
           0.96042183])




```python
inside*4/n
```




    3.139792




```python
inside*4/n
```




    3.139792




```python
np.pi
```




    3.141592653589793



# Contoh

\begin{equation}
g(x) := 4+3x
\end{equation}


```python
x = np.linspace(0,5, 10000)
gx = 4+3*x
x_ = np.random.uniform(low = 0, high = 2, size = 10000)
y = np.random.uniform(low=-0, high = 10, size = 10000)
plt.figure(figsize =(16,16))
plt.plot(x,gx, 'g')
plt.xlim(-3,3)
plt.ylim(-25,25)
plt.grid()
plt.scatter(x_,y, 0.5)
plt.show()
```

\begin{equation}
f(x) := \sin(4x) + \cos(\sin(2x^3))
\end{equation}


```python
x = np.linspace(-5,5, 10000)
fx = np.sin(4*x) + np.cos(np.sin(2*x**3))
x_ = np.random.uniform(low = -5, high = 5, size = 10000)
y = np.random.uniform(low=-0.5, high = 2, size = 10000)
plt.figure(figsize =(16,16))
plt.plot(x,fx, 'g')
plt.scatter(x_,y, 0.5)
plt.show()
```

654131c640f5b9db029f7bb0e2dc2809acb76cef
ipynb
Jupyter Notebook
Materi/random-number.ipynb
leonv1602/mathematics-with-python
8099f0029870b546027d9293847cef642e210217
MIT
Materi/random-number.ipynb
leonv1602/mathematics-with-python
8099f0029870b546027d9293847cef642e210217
MIT
Materi/random-number.ipynb
leonv1602/mathematics-with-python
8099f0029870b546027d9293847cef642e210217
MIT
Qwen/Qwen-72B
1. YES
2. YES