random-sample

Get random lines from large files in bash

有些话、适合烂在心里 提交于 2019-12-10 09:37:47
问题 How can I get n random lines from very large files that can't fit in memory. Also it would be great if I could add filters before or after the randomization. update 1 in my case the specs are : > 100 million lines > 10GB files usual random batch size 10000-30000 512RAM hosted ubuntu server 14.10 so losing a few lines from the file won't be such a big problem as they have a 1 in 10000 chance anyway, but performance and resource consumption would be a problem 回答1: Here's a wee bash function for

Iterative or Lazy Reservoir Sampling

旧巷老猫 提交于 2019-12-09 17:16:28
问题 I'm fairly well acquainted with using Reservoir Sampling to sample from a set of undetermined length in a single pass over the data. One limitation of this approach, in my mind, is that it still requires a pass over the entire data set before any results can be returned. Conceptually this makes sense, since one has to allow items in the entirety of the sequence the opportunity to replace previously encountered items to achieve a uniform sample. Is there a way to be able to yield some random

How to Display Random Data on MySQL using PHP?

两盒软妹~` 提交于 2019-12-08 10:19:24
问题 Hello i have tables like this : Employee EmployeeID EmployeeName 1234 Nayeon 1235 Jihyo 1236 Jungyeon 1237 Dahyun 1238 Sana 1239 Mina 1240 Tzuyu 1241 Chaeyeong 1241 Chaeyeong 1242 Momo i used this source code : <?php mysql_connect("localhost", "root", "1234") or die(mysql_error()); mysql_select_db("databasetransport") or die(mysql_error()); $employees = mysql_query("SELECT * FROM Employee ORDER BY EmployeeID") or die(mysql_error()); $letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $position = 0;

How to Shuffle and Echo 3 Random Words out of a String?

泪湿孤枕 提交于 2019-12-08 03:10:29
问题 a question about getting some random words out of a bigger string after it has been translated: <?=__("water, chicken, banana, rice, bread, salt, cucumber, ananas, peach")?> on my site currently outputs: water, kip, banaan, rijst, zout, komkommer, ananas, perzik now imagine I want to get just 3 words from that on random. How do I do that? It's important not to touch the words parts inside __(" & ") part! The translater cannot process when __($var) but ONLY when __("word1, word2, word3") . I

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

你离开我真会死。 提交于 2019-12-08 02:01:34
问题 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 individuals and not only create a new pointer to the same data. Here is what the code looks like for the moment: ##### Reproduction ###### NewPopulation = Array(Individuals, nb_individuals_in

Julia : generating unique random integer array

天大地大妈咪最大 提交于 2019-12-06 19:09:00
问题 I am trying to create 10 element array of unique random integers. However I am unable to create array with unique values. Is there in Julia something like Pythons sample function ? numbers = zeros(Array(Int64, 10)) rand!(1:100, numbers) Thanks. 回答1: There is a sample function in StatsBase: using StatsBase a = sample(1:100, 10, replace = false) This will draw a sample of length 10 from 1:100 without replacement. 回答2: If performance is not an issue (i.e. the sample range isn't too large, or the

How to get Random values for LogicalTypes

不羁的心 提交于 2019-12-06 03:34:26
问题 I have a tool that generate entities I need to generate a samlpe value for testing. the problem is that we have alot of logical types (some of the same type but still different) and befor coding i wanted to know if someone have a easier solution... Here is the Enum : public enum LogicalTypeEnum { Identity, DateAndTime, Binary, Quantity, Comment, Money, Rate, TimeStamp, Caption, Reference, Number, Weight, Space, Username, Phone, Email, ZipCode } Thanks!!! EDIT 1: I want to generate a random

Get random lines from large files in bash

余生长醉 提交于 2019-12-05 21:36:33
How can I get n random lines from very large files that can't fit in memory. Also it would be great if I could add filters before or after the randomization. update 1 in my case the specs are : > 100 million lines > 10GB files usual random batch size 10000-30000 512RAM hosted ubuntu server 14.10 so losing a few lines from the file won't be such a big problem as they have a 1 in 10000 chance anyway, but performance and resource consumption would be a problem Here's a wee bash function for you. It grabs, as you say, a "batch" of lines, with a random start point within a file. randline() { local

SQL random sample with groups

和自甴很熟 提交于 2019-12-05 21:02:05
问题 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 top 500 id from degree where coursecode = 1 order by newid() union select top 300 id from degree where coursecode = 2 order by newid() union select top 200 id from degree where coursecode = 3 order by newid() but we

R - random distribution with predefined min, max, mean, and sd values

扶醉桌前 提交于 2019-12-05 18:05:34
I want to generate a random distribution of say 10,000 numbers with predefined min, max, mean, and sd values. I have followed this link setting upper and lower limits in rnorm to get random distribution with fixed min and max values. However, in doing so, mean value changes. For example, #Function to generate values between a lower limit and an upper limit. mysamp <- function(n, m, s, lwr, upr, nnorm) { set.seed(1) samp <- rnorm(nnorm, m, s) samp <- samp[samp >= lwr & samp <= upr] if (length(samp) >= n) { return(sample(samp, n)) } stop(simpleError("Not enough values to sample from. Try