In this program, the user will enter the total amount of numbers in a list. the random module will generate random numbers between 1 to 30. Then all the numbers from the list will be added together. I’ve tried to use the variable x but it doesn’t give the results I want, does anyone know a better/…
Tag: random
Trying to show all numbers lower than the average in another list
For school we have to make a code which shows the average of a certain list into another list but for some reason my list which should show the smaller numbers is empty, I don’t know if it is possible but I tried using an extra variable which counts +1 to itself help is appreciated in advance. Answer 2 …
Generating dictionary does not always work
I am trying to generate a dictionary automatically with a for loop (i < numero_usuarios), the keys are taken from a list with names, and the values are randomly generated with a random.randint(1, 10), the problem is that it does not always generate the amount I want. For instance, I want to create 10 users…
How to generate random binary numbers 0 or 1 with length of N and with option to control the probability of having 0 or 1?
I want to generate random binary numbers (0 or 1) having N length size. The tricky part is that, It should be able to control the probability of having either more 1 or 0. For example, I want total 100 random numbers with 0 having probability of 40% and 1 having probability of 60%. Please help. Answer A gener…
Assigning keys and storing in a dictionary Python
For an event of rolling a six-sided die. I need to randomly simulate the event 1000 times and plot a histogram of results for each number on the dice. I want to assign the results for each number to a key of the same value (1 for number of 1s{1:164…}). I need help assigning keys and storing everyting in…
Why does “random.choices” return always the same element when passing a list “cum_weights” of decreasing values?
I don’t understand the cum_weights parameter of random.choices. I read that it is: Weight of previous element + own weight [10, 5, 1] → [10, 15, 16] So as I understand it, the probability of “cherry” is 16 and it is the highest. So why is “apple” more repetitive as a result? outp…
How do I randomly select multiple images from folders and then layer them as a single image in Python?
I’m trying to use python to create a composite .png of randomly selected and layered png’s all with transparent backgrounds, so all layers are visible in the finished piece. For example using different coloured circles of decreasing size: a folder of the largest circles called ‘layer1’…
Random numbers, small decimals
I’m working with random numbers in python, the problem is the following; I have a variable, we can call it “x”, I want it to take values between [10^-6,10^-1], then I have the following line But it is only generating numbers like It never generates numbers like How can I generate the second …
sending random messages with smtplib python
I want to send random messages using smtplib in python, I wrote this code: I’ve received the messages but with the same string, I also tried to make a list of random strings and then make the message variable chose randomly from there using random.choice() but it didn’t work either. What could the…
Seedable CSPRNG for python?
With the random module, you are able to seed it to get the same values every time. Is there a CSPRNG that can do this? For example, according to this question How can I create a random number that is cryptographically secure in python?, random.SystemRandom is secure. But seeding it doesn’t return the sa…