mercredi 23 septembre 2020

print average of a generated list

I'm trying to generate a list of integers length n n is inputted by the user. Then print the smallest and largest number and the average of the list.

I've managed to get it to generate the numbers and print the smallest and largest number. I've tried to divide the list by the items but I'm a bit stuck. I think maybe my logic is off?

e = int(input("enter a num: "))
import random
randomlist = []
for i in range(e):
    n = random.randint(1,101)
    randomlist.append(n)
    avg = randomlist/e
print("generated values:",randomlist)
print (min(randomlist),max(randomlist),avg(randomlist))



Random Pair Generator: How to stop people coming up multiple times?

I am creating a tiny little python programme that needs to generate random pairs for some group work I am organising. I need to make sure people and pairs don't appear twice.

Here is what I have written so far. I feel close but don't quite know how to fix it.

I am getting two lists of people I need to pair together from two .txt files and they are being randomly generated no problem. But I am getting repeats in the output.

I am currently going down the route of creating lists and checking if they are in that list but is there a simpler way?

import random

def split_file(file_name):
  text = open(file_name)
  line = text.read()
  result = line.split("\n")
  return result

mentors = split_file(file_name="mentors.txt")
mentees = split_file(file_name="mentees.txt")

def randomiser(group):
  random_member = random.choice(group)
  return random_member

pairings = []
mentees_list = []
mentors_list = []

for i in range(20):
  mentee = randomiser(mentees)
  if mentee not in mentees_list:
     mentees_list.append(mentee)
  mentor = randomiser(mentors)
  if mentor not in mentors_list:
    mentees_list.append(mentee)
  pair = mentee + ", " + mentor
  if pair not in pairings:
      pairings.append(pair)
      print(pair)



is it possible to predict machine generated powerball number if i have a couple years of data? [closed]

As it said in the title. If I have more than 2 years of data for power ball result, and this power ball number is generated by the machine(which I can assume that it is not fully "random"). Is it possible to predict the next power ball number? If so, what would be the best training and algorithm for it?




Generate a random number between a min and max in BigQuery

I'm trying to use BigQuery to generate a random number between 40,000 and 50,957. But I have no idea how to do this; in Snowflake I'd use something like:

select uniform(40000, 50957, random())

But in BigQuery, the RAND() function only generates a random number between 0 and 1. How would I turn this into something that is between 40,000 and 50,957? I'm sure it is probably a matter of figure out the maths but I failed that in highschool so ¯\(ツ)




Draw random number using Poisson distribution in Python

I am trying to mimic a chance encounter and I'm not sure how to do this. I would like to use a poisson distribution, but am open to other suggestions.

The idea is this: there is a central place where you can meet people. If there are 10 (the minimum) people at this place, the chance is 100% you will meet a specific person (e.g. chance = 1). If there are 6000 (the maximum) people at this place, the chance you will meet everyone is 3.5% you will meet a specific person (e.g. chance = 0.035). How can I implement this using Python?




How to select an already created random true Boolean variable

Lets say I have four Boolean Variables,

Boolean a;
Boolean b;
Boolean c;
Boolean d;

Now before I want to select on of these variables, I run a function to find out if they are true or not (Not relevant why they are true or false, using for other aspect of project);

So lets say,

a = false;
b = true;
c = false;
d = true;

because b and d are the true variables I want to randomly select on of these two. And if three variables are true, then I would want to randomly select one from those three.

I am lost how I would be able to accomplish this.




How many random generators should I create

I am writing a code which requires to uniformly generate random numbers out of several given for different tasks. For example consider:

p = [0,1,2,3]
wt = [0.1,0.7,0.2,0.5]
random.seed = inputseed
random.choices(population=p, weights=wt)

Seed is fixed for all tasks.

Do I need to create separate random generator for each tasks for samples for those tasks to be uniformly random independent of other tasks? Something like this:

rgen = random.Random(inputseed)
rgen.choices(population=p, weights=wt)

Is there any more consideration while using random for more than one logical tasks and also in multi threaded environment?

PS: I am on python-3.8.2