Geneating random number with condition

37 views
Skip to first unread message

Dr. Jamaluddeen (Jamal)

unread,
Jun 16, 2023, 9:00:12 AM6/16/23
to dataanalys...@googlegroups.com
Dear members,
Is there any way to generate random numbers with the condition of the percentage of numbers should be in a certain range; like, 10% of numbers should be (0-70); 20% of numbers should be (70-90) and the remaining 70% should be (90-100). 
I can do it separately, but again allotting the position to a specific number becomes difficult.
Please, guide.
-----
Thanks & Regards,
Dr. Jamaluddeen 
Assistant Professor
Department of Commerce
University of North Bengal
Siliguri, Darjeeling 
West Bengal - 734013
Mobile: (+91)-74  99 61  51  56
___________________________________________________________________________________
"The mediocre teacher tells, the good teacher explains, the superior teacher demonstrates and the great teacher inspires."  ― Charles William Eliot

Arvind Vidyarthy

unread,
Jun 17, 2023, 5:50:22 AM6/17/23
to dataanalys...@googlegroups.com
Dear Dr. Jamaluddeen,
Here is the Python code [ Use this website:https://www.programiz.com/python-programming/online-compiler/].
______________________________________________________________________________________
import random
from collections import defaultdict

def generate_random_numbers(num_samples):
    numbers = []
    frequency_table = defaultdict(int)

    # Generate numbers for the desired percentages
    for _ in range(int(num_samples * 0.1)):
        number = random.uniform(0, 69.999999999999)
        numbers.append(number)
        frequency_table["0-69.999999999999"] += 1

    for _ in range(int(num_samples * 0.2)):
        number = random.uniform(70, 89.99999999)
        numbers.append(number)
        frequency_table["70-89.99999999"] += 1

    for _ in range(int(num_samples * 0.7)):
        number = random.uniform(90, 100)
        numbers.append(number)
        frequency_table["90-100"] += 1

    return numbers, frequency_table

# Generate 100 random numbers with the specified percentages
random_numbers, freq_table = generate_random_numbers(100)

# Print the generated random numbers
print("Generated random numbers:")
print(random_numbers)

# Print the frequency table
print("\nFrequency Table:")
for range_, count in freq_table.items():
    print(f"{range_}: {count}")
_____________________________________________________________________

--
The members of this group are expected to follow the following Protocols:
1. Please search previous posts in the group before posting the question.
2. Don't write the query in someone's post. Always use the option of New topic for the new question. You can do this by writing to dataanaly...@googlegroups.com
3. It’s better to give a proper subject to your post/query. It'll help others while searching.
4. Never write Open-ended queries. This group intends to help research scholars, NOT TO WORK FOR THEM.
5. Never write words like URGENT in your posts. People will help when they are free.
6. Never upload any information about National Seminars/Conferences. Send such information
in personal emails and feel free to share any RESEARCH-related information.
7. No Happy New Year, Happy Diwali, Happy Holi, Happy Birthday, Happy Anniversary, etc. allowed in this group.
8. Asking or sharing Research Papers is NOT ALLOWED.
9. You can share your questionnaire only once.
---
You received this message because you are subscribed to the Google Groups "DataAnalysis" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dataanalysistrai...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dataanalysistraining/CAD4bJ7uF1Zc6%3D2VOjMwTiEHRhVzP1N15_s7Fw01GPoc0HmjzhA%40mail.gmail.com.


--

Thanks & Regards

Arvind Kumar Vidyarthy
Contact No: +91-9608791779
Ph.D. (Industrial Engg. & Management)
Indian Institute Of Technology (ISM), Dhanbad

Dr. Jamaluddeen (Jamal)

unread,
Jun 17, 2023, 11:49:22 PM6/17/23
to dataanalys...@googlegroups.com
Thanks a lot, Sir
The best thing I found is that there is no need to install it like other software.

-----
Thanks & Regards,
Dr. Jamaluddeen 
Assistant Professor
Department of Commerce
University of North Bengal
Siliguri, Darjeeling 
West Bengal - 734013
Mobile: (+91)-74  99 61  51  56
___________________________________________________________________________________
"The mediocre teacher tells, the good teacher explains, the superior teacher demonstrates and the great teacher inspires."  ― Charles William Eliot


Neeraj Kaushik

unread,
Jun 18, 2023, 5:29:09 AM6/18/23
to dataanalys...@googlegroups.com
It is seriously amazing!
This webpage also provides the online page for working on R too.

Arvind Vidyarthy

unread,
Jun 19, 2023, 8:14:41 PM6/19/23
to dataanalys...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages