Replace NA with random weighted value by group

I want to replace the NAs in a variable with a weighted random sample of the values within a given group. Rough sample data: A tibble: 16 × 3 letter number code <chr> <int> <chr> 1 a 1 w1 2 a 1 w1 3 a 1 w2 4 a 1 NA 5 a 2 x1… Read More Replace NA with random weighted value by group

How can I generate cryptographically strong random strings with a given length

I need to generate cryptographically strong random alphanumeric strings with a specified length, only using the following characters. A-Z a-z 0-9 Is there a way to accomplish this in C#? >Solution : You can use class RandomNumberGenerator to generate cryptographically-secure random numbers to do this, for example: string allowed = "ABCDEFGHIJKLMONOPQRSTUVWXYZabcdefghijklmonopqrstuvwxyz0123456789"; int strlen = 10;… Read More How can I generate cryptographically strong random strings with a given length

Trying to exclude an elements in an array if it overlaps with another array in Python

I am writing code that pseudorandomises positions from an array: centre_pos = [‘A’,’B’,’C’,’D’,’E’] corner_pos = [‘1′,’2′,’3′,’4’] def position_generator(): #for centre, corner in zip(centre_pos, corner_pos): random_centre = random.choice(centre_pos) random_corner = random.choice(corner_pos) #if random_centre and random_corner in exclusion: #else: return random_centre, random_corner However, I want to exclude certain combinations of centre_pos and corner_pos. For example if B… Read More Trying to exclude an elements in an array if it overlaps with another array in Python

To add and remove random letters to/from each word in a given string

The following code generates random typos: # https://stackoverflow.com/a/51080546 import string import random phrase = "Lorem ipsum dolor sit amet, lorem ipsum." # probability for a word to change p = 0.8 new_phrase = [] words = phrase.split(‘ ‘) for word in words: outcome = random.random() if outcome <= p: ix = random.choice(range(len(word))) new_word = ”.join([word[w]… Read More To add and remove random letters to/from each word in a given string

Better alternatives to random_device in C++?

I have been using random_device rd{} to generate seeds for my Mersenne-Twister pseudo random number generator mt19937 RNG{rd()} as have been suggested here. However, it is written in the documentation (comment in the documentations’ example code), that "the performance of many implementations of random_device degrades sharply once the entropy pool is exhausted. For practical use… Read More Better alternatives to random_device in C++?

How can i disarrange this list to add into new DatFrame column

I want to create new column in DataFrame which contains following list but not in arranged format that is already in list, It should have to put value in new column randomly. LIST : [‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’, ‘ABC’,… Read More How can i disarrange this list to add into new DatFrame column