vendredi 2 décembre 2022

Hidden Friend in Python

I'm trying to create a hidden friend for my company. In this logic, they will fill out a google forms form and, at the end of the week, I will download it to my computer as a csv file. the data collected are: Full name, email address and desired gift. The idea is to automate the draw and each member will receive a secret friend in their email, with an email address to present them with a virtual gift.

At the stage I'm at, I'm putting together the logic of the draw, but I'm not managing to develop. Because it's not making sense of the draw. One person is drawing two and it should only be one at a time.

import glob
import random
import csv
from itertools import permutations, combinations_with_replacement, combinations


all_list = []
for glob in glob.glob("random_friend/csv/*"):
    file1 = open(glob, "r+")
    reader = csv.reader(file1, delimiter=',')
    for i in reader:
        all_list.append(i)
    all_list.pop(0)

perm = permutations(all_list)

gift = random.choice(['chocolat', 'Squeeze', 'fridge magnet', 'popcorn door cushion kit', 'cocktail shaker kit', 'Suspense book'])

print(gift)

for i in perm:
    name_one = i[1][1]
    name_two = i[2][1]
    mail_one = i[1][2]
    mail_two = i[2][2]

    print(f"""{name_one} took {name_two} and present with a {gift} and send it by e-mail to {mail_two}""")



BigQuery Distinct reorders random ordering

I want to shuffle my query results randomly using ORDER BY RAND(), but when using DISTINCT the ordering statement seems to be ignored.

Code to reproduce:

WITH tmp AS (
SELECT 'aa' cardno
UNION ALL
SELECT 'bb' cardno
UNION ALL
SELECT 'cc' cardno
UNION ALL
SELECT 'dd' cardno
UNION ALL
SELECT 'ee' cardno
UNION ALL
SELECT 'ff' cardno
UNION ALL
SELECT 'gg' cardno
UNION ALL
SELECT 'hh' cardno
)

SELECT DISTINCT cardno FROM
(
SELECT *, RAND() rnd FROM tmp
ORDER BY 2
)

The results are ordered alphabetically, not random as expected. Im using Google cloud platform BigQuery




How can I make an array of random numbers in a range without repeating numbers using a Do... while loop? [duplicate]

I'm creating a random number generator in JavaScript for lotto numbers. This numbers must be in a range of 1 - 50 and then sort them from smallest to largest. I already managed to do that using a do while loop but now I'm having some trouble for the repeated numbers.

I tried an If statement for compare the new number with the previous one, but the code is not working properly and the numbers are repeating

Here is my code block


const randomNumber = (minRange, maxRange) => {
    return Math.floor(Math.random() * (maxRange - minRange + 1) + minRange);
};

// numbers added in order in lottoNumbers array
let lottoNumbers = [];
let num = 0;

do {
    num = randomNumber(1, 50);
    lottoNumbers.push(num);
    if(!lottoNumbers.includes(num)) {
        lottoNumbers.push(num);
    }
    lottoNumbers.sort(function(a, b) {return a - b});
} while (lottoNumbers.length < 5);




Use Random function for send.key different values to two different fields

I want send.key different xpaths’ and need two different random number but when create random number it sent same values to xpaths’ for ex. i want send a and B fields keys and a >b and values should be generated random

I expected send.key two different values but sent same random value




jeudi 1 décembre 2022

Difference between numpy.random.rand() and numpy.random.random_sample()

what is the Difference between numpy.random.rand() and numpy.random.random_sample().

Both of them give the same result.




How do I set a variable with the value being a random range, with variables set to have a random range?

I have this variable called "number" with the range being the variables "a" and "b". These range variables are ranges themselves.

from random import *

a = randint(1, 99)
b = randint(2, 100)

number = randint(a, b)
print(number)

When I try to enter this code, I occasionally receive an integer or get this error:

Traceback (most recent call last):
  File "main.py", line 6, in <module>
    number = randint(a, b)
  File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/random.py", line 248, in randint
    return self.randrange(a, b+1)
  File "/nix/store/2vm88xw7513h9pyjyafw32cps51b0ia1-python3-3.8.12/lib/python3.8/random.py", line 226, in randrange
    raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (17, 6, -11)



mercredi 30 novembre 2022

How can I generate pseudo random sequence of binary number using Hopefield neural network?

For some work, I need to generate a sequence of random binary patterns using the Hopefield neural network. Like I want to generate a 42-bit long binary sequence such as '11101100011100111001100011001110001010001' How can I generate it?

I have tried several ways but no proper solution is coming out.