File size: 1,880 Bytes
99613f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import random

def perform_sampling(population_size, sample_size, seed=None):
    if seed is not None:
        random.seed(seed)
    population = list(range(1, population_size + 1))
    if sample_size > population_size:
        st.error("Sample size cannot be greater than population size.")
        return None
    sample = random.sample(population, sample_size)
    return sample

def main():
    # Sidebar for user inputs
    st.sidebar.title("Input Parameters")
    population_size = st.sidebar.number_input('Enter Population Size', min_value=1, value=1000, step=1)
    sample_size = st.sidebar.number_input('Enter Sample Size', min_value=1, value=50, step=1)
    seed = st.sidebar.number_input('Enter Random Seed (optional)', min_value=0, value=None, step=1, format='%d', key='seed')

    # Main screen for title, description, and output
    st.title('Simple Random Sampling App')
    st.markdown("""
        ## Description
        This application performs simple random sampling on a specified population. Enter the population size,
        sample size, and an optional random seed in the sidebar and press 'Generate Sample' to see the results.
        
        ## Instructions
        - **Population Size**: Total number of items in your population.
        - **Sample Size**: Number of items to randomly select from your population.
        - **Random Seed**: A seed value to ensure reproducibility of your sample.
    """)

    if st.sidebar.button('Generate Sample'):
        sample = perform_sampling(population_size, sample_size, seed)
        if sample is not None:
            st.write(f'### Random Sample Output')
            st.write(f'Random Sample: {sample}')
            st.write(f'Sample Size: {len(sample)}')
            if seed is not None:
                st.write(f'Random Seed Used: {seed}')

if __name__ == '__main__':
    main()