vendredi 1 février 2019

How to create a new list that is combination of 2 different lists elements without repetition?

I am trying to create a canvas that has 2 stimulis. Please note that stimuli lists can be longer.

sti1 = ["death", "pain"]
sti2 = ["glass", "book"]

These stimulis will shown like this:

frame 1: death - book / frame 2: glass - pain

But they must shuffle correctly. I mean if there is a "death x book" combination, there must not be another one. Also, all combinations must be shown. Also, all frames must contain one word from sti1 and one word from sti2.

Here is what I thought:

  1. create a combination list that contains all the combinations.

  2. use for loop to itarate.

If there is another solution than creating a combination list and iterate it, I am open to new things.

I tried: random.choice itertools.permutations itertools.combinations (most close answer but this just can combine 1 list like sti1)

Expected result: combination_list = [(death, glass), (death, book), (pain, glass), (pain, book)]




I need to generate 1000 matrices of randoms numers between 0 and 2 in C

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int random[3][3];
    int i, j, n;

    for (n = 0; n < 1000; n++)
    {
        srand(time(NULL));

        for(i = 0; i<3; i++){
            for(j = 0; j<3; j++)
            {
                random[i][j] = rand()%3;
                for (n = 0; n < 1000; n++)
                {
                    for(i = 0; i<3; i++){
                        for(j = 0; j<3; j++)
                        {
                            printf("%d", random[i][j]);
                        }
                    }
                }
            }
        }
    }
    return 0;
}




How to Generate a 'Future-Index' Pseudo-Random Number Without Generating Its Preceding Numbers

Context:

Let's consider a random-number set of 10 integer elements generated by one of the PRNG-C++ approaches using a fixed seed integer, i.e. const int seedMe = 31:

0 1 2 3 4 5 6 7 8 9

Question:

Assuming pseudo-random number generators generate fixed number sequences, which are determined by the seed.

  • For the known seed (seedMe) and the known set size (10), is it conceptually possible to generate the random number corresponding to the index N in advance? For example, generation of the 3rd element of the above set without generating the preceding 0 1 2.
  • If so, is there any practical example of such practice in C++?

Aim of the Question:

For known seed and set size, in my parallel computations, a 1-D random-number global-set is needed, which should be the same for each processor.

Each processor uses a subset of the global-set, and accordingly, a priori knows the global-set indices for the subset. For example, for a 2-processor computation, the first processor needs only i = [0, 4] indexed-random numbers, and the second proc i = [5, 9] indexed ones.

I wonder if we can directly and locally generate the subsets of a global-PRNG set at each processor, hence the discard of any need for parallel communication of any sort.




How to generate random data off of existing sample data?

I have a set of existing data, lets say:

sample_data = [2,2,2,2,2,2,3,3,3,3,4,4,4,4,4]

off of this sample data, i would like to generate a random set of data of a certain length.




How to generate random characters in Python without repeating?

Using something similar, how do I generate random characters without repetition?

random.choice(string.ascii_letters)




How to filter every 10th record in Excel? But that record may have multiple rows

I need to do random sampling and choose every 10th record. However, that record may have multiple rows. I need to be able to get all of those rows that belong to that record and paste it into a new sheet. I am very new to VBA, but I would like to get a code that can help me do this. Thank you in advance.




SQL Query for Random 10% with a minimum of 20 rows

I have been tasked with generating a report that will randomly pick 10% of a unique ID, unless 10% is less than 20 items in which case the report would pick 20 random ID's. I have been using NewID to generate the 10%, but that really isn't the best as it gives me variable results (IE: more or less than 10%)

Code also includes my attempts to get a total count of the results:

select  UniqueID, TotalCount = Count(*) Over(), SUM(COUNT(UniqueID)) OVER() 
AS total_count 
from table 
where 0.15 >= CAST(CHECKSUM(NEWID(), UniqueID) & 0x7fffffff AS float) / CAST (0x7fffffff AS int)
group by UniqueID