File size: 2,006 Bytes
9f27dc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import streamlit as st
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from io import BytesIO

# Title of the App
st.title("Random Data Generator")

# Sidebar for User Inputs
st.sidebar.header("Settings")

# Distribution Selector
distribution = st.sidebar.selectbox(
"Select a Distribution",
["Uniform", "Bernoulli", "Gaussian", "Discrete"]
)

# Number of Data Points
n_points = st.sidebar.number_input(
"Number of Data Points", min_value=1, max_value=1000000, value=1000, step=1000
)

# Parameters for Distributions
if distribution == "Uniform":
    low = st.sidebar.number_input("Lower Bound", value=0.0)
    high = st.sidebar.number_input("Upper Bound", value=1.0)
    data = np.random.uniform(low, high, n_points)

elif distribution == "Bernoulli":
    p = st.sidebar.slider("Probability (p)", min_value=0.0, max_value=1.0, value=0.5)
    data = np.random.binomial(1, p, n_points)

elif distribution == "Gaussian":
    mean = st.sidebar.number_input("Mean", value=0.0)
    std_dev = st.sidebar.number_input("Standard Deviation", value=1.0)
    data = np.random.normal(mean, std_dev, n_points)

elif distribution == "Discrete":
    low = st.sidebar.number_input("Lower Bound", value=0)
    high = st.sidebar.number_input("Upper Bound", value=10)
    data = np.random.randint(low, high + 1, n_points)


# Visualization
st.write("### Visualization")
fig, ax = plt.subplots()
ax.hist(data, bins=30, alpha=0.75, color="skyblue", edgecolor="black")
ax.set_title(f"Histogram of {distribution} Distribution")
ax.set_xlabel("Value")
ax.set_ylabel("Frequency")
st.pyplot(fig)


# Display the Generated Data
st.write(f"### {distribution} Distribution - {n_points} Points")
df = pd.DataFrame(data, columns=["Value"])
st.dataframe(df)

with st.sidebar:
    # Download the Data
    st.write("### Download Data")
    csv = df.to_csv(index=False).encode("utf-8")
    st.download_button(
    label="Download CSV",
    data=csv,
    file_name=f"{distribution}_data.csv",
    mime="text/csv",
    )