Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8496127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:45:57+00:00 2026-06-10T23:45:57+00:00

Possible Duplicate: Weighted random selection with and without replacement I tired to make all

  • 0

Possible Duplicate:
Weighted random selection with and without replacement

I tired to make all decisions what to do next by myself. I want computer to do it.
I only write things and give priority to each, computer selects one by these priorities with random element.

So, I made this file (tsv):

3   work A
2   work B
1   work C
1   laundry
1   nothing

“Work A” should happens with 38% probability. “nothing” – 13%, etc.
Computer should count all this and say to me: do ___

I can read it and get percents for each thing. But I cannot figure out how should I select one thing with these percents.

import csv

# reading
file = open('do.txt', mode='r', encoding='utf-8')
tsv_file = csv.reader(file, delimiter='\t')

# total priority
priority_total = 0
for work in tsv_file:
    priority_total = priority_total + int(work[0])

?????

print(do_this)

What is the way to do this? Is there a function for random selection with given probabilities?

I really need this to stop procrastinating and start doing things.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:45:59+00:00Added an answer on June 10, 2026 at 11:45 pm

    Well, a simple approach would be to create a list of your tasks, but add each task a number of times to the list equal to its priority.

    So after loading your file, the list would look like this:

    ['work A', 'work A', 'work A', 'work B', 'work B', 'work C', 'laundry', 'nothing']
    

    and then you can use random.choice to select a random element.

    task_list = []
    for prio, work in tsv_file:
        task_list += [work] * int(prio)
    
    do_this = random.choice(task_list)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How to do the vector of sets in C++? I want to
Possible Duplicate: check whether internet connection is available with C# I just want to
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always
Possible Duplicate: How do pointer to pointers work in C? Hi All, I have
Possible Duplicate: How to change stack size for a .NET program? I want to
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
Possible Duplicate: Detect inside Android Browser or WebView i want to detect whether the
Possible Duplicate: Trying to get tables next to each other horizontal I have two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.