random

How to pythonically select a random index from a 2D list such that the corresponding element matches a value?

旧城冷巷雨未停 提交于 2021-02-19 23:44:40
问题 I have a 2D list of booleans. I want to select a random index from the the list where the value is False . For example, given the following list: [[True, False, False], [True, True, True], [False, True, True]] The valid choices would be: [0, 1] , [0, 2] , and [2, 0] . I could keep a list of valid indices and then use random.choice to select from it, but it seems unpythonic to keep a variable and update it every time the underlying list changes for only this one purpose. Bonus points if your

How to pythonically select a random index from a 2D list such that the corresponding element matches a value?

╄→尐↘猪︶ㄣ 提交于 2021-02-19 23:41:08
问题 I have a 2D list of booleans. I want to select a random index from the the list where the value is False . For example, given the following list: [[True, False, False], [True, True, True], [False, True, True]] The valid choices would be: [0, 1] , [0, 2] , and [2, 0] . I could keep a list of valid indices and then use random.choice to select from it, but it seems unpythonic to keep a variable and update it every time the underlying list changes for only this one purpose. Bonus points if your

How can I shuffle a very large list stored in a file in Python?

纵然是瞬间 提交于 2021-02-19 08:11:48
问题 I need to deterministically generate a randomized list containing the numbers from 0 to 2^32-1. This would be the naive (and totally nonfunctional) way of doing it, just so it's clear what I'm wanting. import random numbers = range(2**32) random.seed(0) random.shuffle(numbers) I've tried making the list with numpy.arange() and using pycrypto's random.shuffle() to shuffle it. Making the list ate up about 8gb of ram, then shuffling raised that to around 25gb. I only have 32gb to give. But that

Matlab: Array of random integers with no direct repetition

早过忘川 提交于 2021-02-19 05:22:25
问题 For my experiment I have 20 categories which contain 9 pictures each. I want to show these pictures in a pseudo-random sequence where the only constraint to randomness is that one image may not be followed directly by one of the same category. So I need something similar to r = randi([1 20],1,180); just with an added constraint of two numbers not directly following each other. E.g. 14 8 15 15 7 16 6 4 1 8 is not legitimate, whereas 14 8 15 7 15 16 6 4 1 8 would be. An alternative way I was

Matlab: Array of random integers with no direct repetition

怎甘沉沦 提交于 2021-02-19 05:22:08
问题 For my experiment I have 20 categories which contain 9 pictures each. I want to show these pictures in a pseudo-random sequence where the only constraint to randomness is that one image may not be followed directly by one of the same category. So I need something similar to r = randi([1 20],1,180); just with an added constraint of two numbers not directly following each other. E.g. 14 8 15 15 7 16 6 4 1 8 is not legitimate, whereas 14 8 15 7 15 16 6 4 1 8 would be. An alternative way I was

generating a random code in php?

荒凉一梦 提交于 2021-02-18 15:48:48
问题 i know this might seem silly, but i want to generate a random code of 8 characetrs, only numbers or letters using php. i needs this to generate a password for each user that signs up, thanks 回答1: I would rather use md5 to generate passwords But you can use something like this if you want a custom: function createRandomPassword() { $chars = "abcdefghijkmnopqrstuvwxyz023456789"; srand((double)microtime()*1000000); $i = 0; $pass = '' ; while ($i <= 7) { $num = rand() % 33; $tmp = substr($chars,

How does List::Util 'shuffle' actually work?

允我心安 提交于 2021-02-18 12:33:04
问题 I am currently working on building a classifier using c5.0. I have a dataset of 8000 entries and each entry has its own i.d number (1-8000). When testing the performance of the classifier I had to make 5sets of 10:90 (training data: test data) splits. Of course any training cases cannot appear again in the test cases, and duplicates cannot occur in either set. To solve the problem of picking examples at random for the training data, and making sure the same cannot be picked for the test data

Generate 'Random number' variables in JMeter

ぐ巨炮叔叔 提交于 2021-02-18 11:10:47
问题 Is it possible to generate 'Random number' variables in JMeter? I have recorded a user journey I have imported the journey into JMeter I have to type in a unique 4digit id within my user journey test case Its default to 2323 at the moment in jmeter Is there a way of generating a random 4didgit number? For example thread1: ID: 2323 thread2: 3334 thread3: 5643 Please refer to images below: 回答1: Use Random JMeter function ${__Random(0000,9999)} The random function returns a random number that

Generate 'Random number' variables in JMeter

我的未来我决定 提交于 2021-02-18 11:08:57
问题 Is it possible to generate 'Random number' variables in JMeter? I have recorded a user journey I have imported the journey into JMeter I have to type in a unique 4digit id within my user journey test case Its default to 2323 at the moment in jmeter Is there a way of generating a random 4didgit number? For example thread1: ID: 2323 thread2: 3334 thread3: 5643 Please refer to images below: 回答1: Use Random JMeter function ${__Random(0000,9999)} The random function returns a random number that

Generate 'Random number' variables in JMeter

偶尔善良 提交于 2021-02-18 11:08:11
问题 Is it possible to generate 'Random number' variables in JMeter? I have recorded a user journey I have imported the journey into JMeter I have to type in a unique 4digit id within my user journey test case Its default to 2323 at the moment in jmeter Is there a way of generating a random 4didgit number? For example thread1: ID: 2323 thread2: 3334 thread3: 5643 Please refer to images below: 回答1: Use Random JMeter function ${__Random(0000,9999)} The random function returns a random number that