FAQ Database Discussion Community


Generating ID numbers by class for a simulated sample in R

r,simulation,random-sample
I'm trying to simulate ID numbers for population that covers multiple classes with the following parameters Each class assigns IDs sequentially following the same pattern. Each class' ID prefix is different from every other class' prefix. Generate some Example data data(mtcars) set.seed(9999) mtcars$count<-sample(x = 1:100,size = 32,replace=T) mtcars Car.Sample<-sample(1:sum(mtcars$count),15) So,...

Randomly selecting k different numbers in a range

java,algorithm,sorting,random,random-sample
I need to select k elements randomly in the range 0 to n-1. n can be upto 10^9. And k can range from 1 to n-1. I can do this in O(n) time just by shuffling an array containing values 0 to n-1 and choosing first k elements from it....

Reproducing a population. Should I `deepcopy` each individual?

copy,sample,julia-lang,deep-copy,random-sample
I simulate an evolving population in Julia. Somewhere in my code I randomly sample (sample weighted by the fitnesses of the individuals) individuals in order to form the next generation. Because the same individual can be sampled several times (sampling with replacement), I have to make that I copy the...

Java generate random number based on boxplot

java,statistics,boxplot,random-sample
I'm searching for a method or library for java (can be java-8) that is capable of generating a random sample (preferable with a fixed seed for deterministic testing) based on the numbers that make up a boxplot. So imagine having the boxplot: ---------- |-----| | |-----------| ---------- min A avg...

Replicating random normal generated in SAS (rancor) in R, based on the same seed?

r,sas,random-sample
Given the same seed, is there a way to produce the exact same random normal numbers generated in SAS, using the rannor function, in R?

Writing to file in java using BufferedWriter

java,filewriter,random-sample,bufferedwriter,file-writing
I'm trying to take some random samples from a file and do some operations and then write them to another file. But I'm having trouble writing to a file in the grepLine method which can be found below. Inside the while loop of the grepLine function, I get a blank...

Fast, independent random draws / sample from a list in python - fixed probability, not total number

python,numpy,random,pandas,random-sample
I'd like to draw a sample of items from a list, but I want to set the probability each item is included, not the total number of items to draw (so random.sample() does not work). I get the effect I want with the following code (where p is probability of...

Iterator to produce unique random order?

language-agnostic,iterator,random-sample
The problem is stated as follows, we have a very large number of items which are traversed through an iterator pattern (which dynamicaly constructs or fetches) the requested item. Due to the number of items being large and thus cannot be kept in memory (as a list for example). What...

Initialize a random sequence that is the same each time you then refer to it in F#

random,f#,random-sample
I was looking to take a random sample from a sequence by zipping it to a random infinite sequence and doing quickselect on the second element of tuples, but I hit the problem that a sequence initialized with random integers doesn't stay with the same value from the first time...

SQL random sample with groups

sql,sql-server,sample,random-sample
I have a university graduate database and would like to extract a random sample of data of around 1000 records. I want to ensure the sample is representative of the population so would like to include the same proportions of courses eg I could do this using the following: select...

5 letters “word” randomly generated

r,random-sample
I would like to create a vector of 10 "words" made of 5 characters that have been randomly generated. e.g c("ASDT","WUIW"...) At the moment I am using the following script but surely there should be a much better way of doing this result = list() for (i in 1:10){ result[i]<-paste(sample(LETTERS,...

Randomly sample lines retaining commented header lines

bash,random-sample
I'm attempting to randomly sample lines from a (large) file, while always retaining a set of "header lines". Header lines are always at the top of the file and unlike any other lines, begin with a #. The actual file format I'm dealing with is a VCF, but I've kept...

Matlab Distribution Sampling

matlab,distribution,sampling,random-sample
How can I create a vector x in Matlab that has values between 0.8 and 1.2, randomly sampled from a: 1. Uniform 2. Normal distribution? There are a lot of functions dealing with distributions, but I'm having trouble using them properly....

R Shiny: need consistent random sample with each customization

r,shiny,random-sample
This is my first ever question, so apologies in advance if I don't follow any of the site's norms! I'm experimenting with R Shiny. I am attempting to make an application that allows someone to customize a lot of the components of different distributions and kernel estimators. Before I go...

Permutations from columns of a data frame in R with specific conditions

r,random-sample
This may be a rather complex question so if someone can at least point me in the right direction I can probably figure out the rest on my own. Sample data: dat <- data.frame(A = c(1, 4, 5, 3, NA, 5), B = c(6, 5, NA, 5, 3, 5), C...