random

Generating a triangular distribution in Matlab

只愿长相守 提交于 2020-03-21 03:51:58
问题 I have attempted to generate a triangular probability distribution in Matlab, but was not successful. I used the formula at http://en.wikipedia.org/wiki/Triangular_distribution. n = 10000000; a = 0.2; b = 0.7; c = 0.5; u = sqrt(rand(n, 1)); x = zeros(n, 1); for i = 1:n U = u(i); if U < (c-a)/(b-a) X = a + sqrt(U*(b-a)*(c-a)); else X = b - sqrt((1-U)*(b-a)*(b-c)); end x(i) = X; end hist(x, 100); The histogram looks like so: Doesn't look like much of a triangle to me. What's the problem? Am I

Generating a triangular distribution in Matlab

怎甘沉沦 提交于 2020-03-21 03:51:41
问题 I have attempted to generate a triangular probability distribution in Matlab, but was not successful. I used the formula at http://en.wikipedia.org/wiki/Triangular_distribution. n = 10000000; a = 0.2; b = 0.7; c = 0.5; u = sqrt(rand(n, 1)); x = zeros(n, 1); for i = 1:n U = u(i); if U < (c-a)/(b-a) X = a + sqrt(U*(b-a)*(c-a)); else X = b - sqrt((1-U)*(b-a)*(b-c)); end x(i) = X; end hist(x, 100); The histogram looks like so: Doesn't look like much of a triangle to me. What's the problem? Am I

random模块

混江龙づ霸主 提交于 2020-03-19 04:59:19
1)random.random random.random()用于生成一个0到1的随机符点数: 0 <= n < 1.0 2)random.uniform    random.uniform的函数原型为:random.uniform(a, b),用于生成一个指定范围内的随机符点数,两个参数其中一个是上限,一个是下限。 如果a > b,则生成的随机数n: b <= n <= a。 如果 a<b, 则生成的随机数n: a<=n<=b. 3)random.randint   random.randint()的函数原型为:random.randint(a, b),用于生成一个指定范围内的整数。其中参数a是下限,参数b是上限,生成的随机数n: a <= n <= b 4)random.randrange random.randrange的函数原型为:random.randrange([start], stop[, step]),从指定范围内,按指定基数递增的集合中 获取一个随机数。如:random.randrange(10, 100, 2),结果相当于从[10, 12, 14, 16, ... 96, 98]序列中获取一个随机数。random.randrange(10, 100, 2)在结果上与 random.choice(range(10, 100, 2) 等效 5)random

【tensorflow】中tf.random.uniform用法

北城以北 提交于 2020-03-17 22:45:21
# 定义一个随机数(标量) random_float = tf . random . uniform ( shape = ( ) ) tf . random . uniform ( ) 的常用用法是产生一个随机数 当()里shape指定大小时,比如shape = ( 6 , 6 ) 例如: random_float = tf . random . uniform ( shape = ( 6 , 6 ) ) 输出: random_float tf . Tensor ( [ [ 0.5413165 0.9985248 0.81406665 0.24037695 0.5445132 0.8941165 ] [ 0.72098756 0.26960266 0.16734755 0.6911627 0.4066162 0.9881915 ] [ 0.8730695 0.48352456 0.00285757 0.81027746 0.17887259 0.7702277 ] [ 0.14711106 0.20008647 0.7115674 0.13419867 0.76057637 0.25808132 ] [ 0.22025907 0.97988033 0.33997393 0.96810377 0.02345192 0.22615612 ] [ 0.13810503 0

模块collections,time,random,sys模块

别说谁变了你拦得住时间么 提交于 2020-03-17 06:17:34
一、collections模块 # from collections import OrderedDict# d = OrderedDict()# d['a'] = 1# d['z'] = 2# d['b'] = 3# print(d)## d['z'] = 0# print(d)# {'apple':100,'computer':10000}# 默认字典# 有如下值集合 [11,22,33,44,55,66,77,88,99,90...],# 将所有大于 66 的值保存至字典的第一个key中,# 将小于 66 的值保存至第二个key的值中。# dic = {}# l = [11,22,33,44,55,66,77,88,99,90]# for i in l:# if i>66:# if dic.get('k1'):# dic['k1'].append(i)# else:# dic['k1'] = [i]# elif i<66:# if dic.get('k2'):# dic['k2'].append(i)# else:# dic['k2'] = [i]# print(dic)from collections import defaultdict# d = defaultdict(set)# print(d)# print(d['a'])# d['b'] = 10# print(d

How to randomize seed in C# [duplicate]

醉酒当歌 提交于 2020-03-15 07:51:31
问题 This question already has answers here : How do I generate a random int number? (32 answers) Closed 3 years ago . I need to generate random int in C#. I am using clock time to set the seend. However, as the rnd.Next() function may take less than a millisecond, this does not work if one has to generate a list of ints. for( int i=0; i<5; i++) { int max_val = 10; // max value var rnd = new Random(DateTime.Now.Millisecond); int randind = rnd.Next(0, max_val); Console.WriteLine(randind); } Output:

Cryptograhically random unique strings

北战南征 提交于 2020-03-14 18:30:28
问题 In this answer, the below code was posted for creating unique random alphanumeric strings. Could someone clarify for me how exactly they are ensured to be unique in this code and to what extent these are unique? If I rerun this method on different occasions would I still get unique strings? Or did I just misunderstand the reply and these are not generating unique keys at all, only random? I already asked this in a comment to that answer but the user seems to be inactive. public static string

Cryptograhically random unique strings

半城伤御伤魂 提交于 2020-03-14 18:26:54
问题 In this answer, the below code was posted for creating unique random alphanumeric strings. Could someone clarify for me how exactly they are ensured to be unique in this code and to what extent these are unique? If I rerun this method on different occasions would I still get unique strings? Or did I just misunderstand the reply and these are not generating unique keys at all, only random? I already asked this in a comment to that answer but the user seems to be inactive. public static string

模块简介:(random)(xml,json,pickle,shelve)(time,datetime)(os,sys)(shutil)(pyYamal,configparser)(hashlib)

北城以北 提交于 2020-03-14 09:42:54
Random模块: #!/usr/bin/env python #_*_encoding: utf-8_*_ import random print (random.random()) #0.6445010863311293 #random.random()用于生成一个0到1的随机符点数: 0 <= n < 1.0 print (random.randint(1,7)) #4 #random.randint()的函数原型为:random.randint(a, b),用于生成一个指定范围内的整数。 # 其中参数a是下限,参数b是上限,生成的随机数n: a <= n <= b print (random.randrange(1,10)) #5 #random.randrange的函数原型为:random.randrange([start], stop[, step]), # 从指定范围内,按指定基数递增的集合中 获取一个随机数。如:random.randrange(10, 100, 2), # 结果相当于从[10, 12, 14, 16, ... 96, 98]序列中获取一个随机数。 # random.randrange(10, 100, 2)在结果上与 random.choice(range(10, 100, 2) 等效。 print(random.choice('liukuni')

C#随机数生成

半腔热情 提交于 2020-03-13 08:17:23
private static char[] constant = { '0','1','2','3','4','5','6','7','8','9', 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' }; public static string GenerateRandomNumber(int Length) { System.Text.StringBuilder newRandom = new System.Text.StringBuilder(62); Random rd = new Random(); for (int i = 0; i < Length; i++) { newRandom.Append(constant[rd.Next(62)]); } return newRandom.ToString(); } 随机数的使用很普遍,可用它随机显示图片,用它防止无聊的人在论坛灌水还可以用来加密信息等等