random

Speed comparison. numpy vs python standard

喜夏-厌秋 提交于 2020-01-01 02:25:13
问题 I made a few experiment and found a number of cases where python's standard random and math library is faster than numpy counterpart. I think there is a tendency that python's standard library is about 10x faster for small scale operation, while numpy is much faster for large scale (vector) operations. My guess is that numpy has some overhead which becomes dominant for small cases. My question is: Is my intuition correct? And will it be in general advisable to use the standard library rather

Random selection from CSV file in Jmeter

一世执手 提交于 2020-01-01 01:55:14
问题 I have a very large CSV file (8000+ items) of URLs that I'm reading with a CSV Data Set Config element. It is populating the path of an HTTP Request sampler and iterating through with a while controller. This is fine except what I want is have each user (thread) to pick a random URL from the CSV URL list. What I don't want is each thread using CSV items sequentially. I was able to achieve this with a Random Order Controller with multiple HTTP Request samplers , however 8000+ HTTP Samplers

Seeding random number generators in parallel programs

本小妞迷上赌 提交于 2020-01-01 01:41:53
问题 I am studing the multiprocessing module of Python. I have two cases: Ex. 1 def Foo(nbr_iter): for step in xrange(int(nbr_iter)) : print random.uniform(0,1) ... from multiprocessing import Pool if __name__ == "__main__": ... pool = Pool(processes=nmr_parallel_block) pool.map(Foo, nbr_trial_per_process) Ex 2. (using numpy) def Foo_np(nbr_iter): np.random.seed() print np.random.uniform(0,1,nbr_iter) In both cases the random number generators are seeded in their forked processes. Why do I have to

PHP - What is a good way to produce a short alphanumeric string from a long md5 hash?

孤者浪人 提交于 2020-01-01 01:33:07
问题 This is for the purpose of having a nice short URL which refers to an md5 hash in a database. I would like to convert something like this: a7d2cd9e0e09bebb6a520af48205ced1 into something like this: hW9lM5f27 Those both contain about the same amount of information. The method doesn't have to be direct and reversible but that would be nice (more flexible). At the least I would want a randomly generated string with the hex hash as the seed so it is reproducible. I'm sure there are many possible

Whats more random, hashlib or urandom?

て烟熏妆下的殇ゞ 提交于 2020-01-01 01:27:06
问题 I'm working on a project with a friend where we need to generate a random hash. Before we had time to discuss, we both came up with different approaches and because they are using different modules, I wanted to ask you all what would be better--if there is such a thing. hashlib.sha1(str(random.random())).hexdigest() or os.urandom(16).encode('hex') Typing this question out has got me thinking that the second method is better. Simple is better than complex. If you agree, how reliable is this

when generating normally-distributed random values, what is the most efficient way to define the range?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 00:43:11
问题 FYI: random == pseudo-random A. when generating uniformly-random numbers, I can specify a range, i.e.: (Math.random()-Math.random())*10+5 //generates numbers between -5 and 15 B. generating a set of random values with a version of Gaussian-esque normal randomness: //pass in the mean and standard deviation function randomNorm(mean, stdev) { return Math.round((Math.random()*2-1)+(Math.random()*2-1)+(Math.random()*2-1))*stdev+mean); } //using the following values: { mean:400, standard_deviation

Java keytool / the security of generated keys with java (in general)

旧时模样 提交于 2019-12-31 23:05:34
问题 We are using the keytool bundled with the java installation to generate keys to do an asymmetric RSA encryption. In the light of recent events somebody asked me whats happening under the hood of the java keytool. Especially regarding the randomness of the resulting numbers. (e.g. "huh why isn't there any random user input taken like mouse movements or keyboard input?" So what are the 'randomness sources' of the java keytool to create its keys? I did a quick research myself however the only

Crappy Random Number Generator

谁都会走 提交于 2019-12-31 22:41:09
问题 This may sound like an odd question, but where can I find a random number generator that works in C or C++ that is not very good? Context: I'm creating some tree graph plotting software and testing it by using multi-digit random numbers (so each digit becomes a node in the tree). The random number generator I've been using - which is the one that comes with the GNU C++ compiler - gives me a nice spread of values. That's good, but I want to see how the table looks when the numbers clump

林轩田机器学习 | 机器学习技法课程笔记10 --- Random Forest

空扰寡人 提交于 2019-12-31 21:28:27
上节课我们主要介绍了Decision Tree模型。Decision Tree算法的核心是通过递归的方式,将数据集不断进行切割,得到子分支,最终形成树的结构。C&RT算法是决策树比较简单和常用的一种算法,其切割的标准是根据纯度来进行,每次切割都是为了让 分支内部纯度最大。最终,决策树不同的分支得到不同的 (即树的叶子,C&RT 算法中, 是常数)。本节课将介绍随机森林(Random Forest)算法,它是我们之前介绍的Bagging和上节课介绍的Decision Tree的结合。 目录 1. Random Forest Algorithm 2. Out-Of-Bag Estimate 3. Feature Selection 4. Random Forest in Action 5. 总结 1. Random Forest Algorithm 首先我们来复习一下之前介绍过的两个机器学习模型:Bagging和Decision Tree。 Bagging是通过bootstrap的方式,从原始的数据集D中得到新的 ;然后再使用一些 base algorithm基于每个 训练得到相应的 ;最后将所有的 通过投票uniform的形式组合成一个G,G即为我们最终得到的模型/假设。Decision Tree是通过递归形式,利用分支条件,将原始数据集D切割成一个个子树结构,长成一棵完整的树形结构

How to really shuffle a deck of cards

时光总嘲笑我的痴心妄想 提交于 2019-12-31 21:20:46
问题 When I need to shuffle a deck of poker cards in Java/Android, I use Collections.shuffle(List<?> list) , of course. I've ever been doing this and the results seemed acceptable. But they aren't. As outlined in this paper, there are 52! possible unique shuffles of a 52 card poker deck. That amounts to about 2^226. But Collections.shuffle(List<?> list) uses new Random() by default which uses a 48-bit seed and can therefore only create 2^48 unique shuffles - which is only 3.49*10^(-52) percent of