random

Vb6 How do I make a Random String of 0-9 and a-z of x characters

纵饮孤独 提交于 2020-01-12 06:58:29
问题 Trying to create a random string, x characters in length using 0-9 and a-z/A-Z and can't seem to find a good example, any ideas? 回答1: Function RandomString(cb As Integer) As String Randomize Dim rgch As String rgch = "abcdefghijklmnopqrstuvwxyz" rgch = rgch & UCase(rgch) & "0123456789" Dim i As Long For i = 1 To cb RandomString = RandomString & Mid$(rgch, Int(Rnd() * Len(rgch) + 1), 1) Next End Function Please be aware that the built-in random number generator is not cryprographically secure

Compatibility of window.crypto.getRandomValues()

£可爱£侵袭症+ 提交于 2020-01-12 06:43:26
问题 I need to generate cryptographically secure pseudorandom numbers, in Javascript. I know about the window.crypto.getRandomValues API, which does exactly what I want. However, I also know it was introduced relatively recently (in 2011 or so). Can I safely assume window.crypto.getRandomValues is present, or will using it introduce compatibility problems on some browsers? Are there any major (widely used) browsers which do not support window.crypto.getRandomValues (including mobile or desktop

MySQL UUID primary key - generated by PHP or by MySQL?

谁都会走 提交于 2020-01-12 05:11:09
问题 I was under the impression that just having MySQL generate the primary key via UUID() would make the key unique across servers, etc. But, there is no way to fetch the last inserted UUID, which requires that an extra select statement be done each time I insert. Is it possible to have PHP generate the exact same UUID() that MySQL would generate? 回答1: No, it's not possible to have PHP generate the exact same UUID() as MySQL because it's a (completely) random number. It sounds like your problem

Is there a way to grab the actual state of System.Random?

佐手、 提交于 2020-01-12 04:57:26
问题 I would like to be able to get the actual state or seed or whatever of System.Random so I can close an app and when the user restarts it, it just "reseeds" it with the stored one and continues like it was never closed. Is it possible? Using Jon's idea I came up with this to test it; static void Main(string[] args) { var obj = new Random(); IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream("c:\\test.txt", FileMode.Create, FileAccess.Write, FileShare.None); formatter

Difference between random draws from scipy.stats…rvs and numpy.random

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-12 04:43:09
问题 It seems if it is the same distribution, drawing random samples from numpy.random is faster than doing so from scipy.stats.-.rvs . I was wondering what causes the speed difference between the two? 回答1: scipy.stats.uniform actually uses numpy, here is the corresponding function in stats (mtrand is an alias for numpy.random) class uniform_gen(rv_continuous): def _rvs(self): return mtrand.uniform(0.0,1.0,self._size) scipy.stats has a bit of overhead for error checking and making the interface

day07_Scanner类、Random类、ArrayList类

笑着哭i 提交于 2020-01-12 02:46:07
API 概述 API(Application Programming Interface),应用程序编程接口。Java API是一本程序员的 字典 ,是JDK中提供给我们使用的类的说明文档。这些类将底层的代码实现封装了起来,我们不需要关心这些类是如何实现的,只需要学习这些类如何使用即可。所以我们可以通过查询API的方式,来学习Java提供的类,并得知如何使用它们。 API使用步骤 打开帮助文档。 点击显示,找到索引,看到输入框。 你要找谁?在输入框里输入,然后回车。 看包。java.lang下的类不需要导包,其他需要。 看类的解释和说明。 学习构造方法 使用成员方法。 引用类型使用步骤 类属于引用类型的一种,所有起使用步骤符合引用类型的使用步骤 1:导包 使用import关键字导包,在类的所有代码之前导包,引入要使用的类型,java.lang包下的所有类无需导入。 格式: 2:创建对象 使用该类的构造方法,创建一个该类的对象。 格式: 3:调用 调用该类的成员方法,完成指定功能。 格式: 举例: 调用该类的成员变量,来获取指定的值 格式: 变量名.成员变量名称 Scanner类 什么是Scanner类 一个可以解析基本类型和字符串的简单文本扫描器。 例如,以下代码使用户能够从 System.in 中读取一个数: //备注:System.in 系统输入指的是通过键盘录入数据。

Groovy: Generate random string from given character set

我是研究僧i 提交于 2020-01-11 15:48:49
问题 Using Groovy, I'd like to generate a random sequence of characters from a given regular expression. Allowed charaters are: [A-Z0-9] Length of generated sequence: 9 Example: A586FT3HS However, I can't find any code snippet which would help me. If using regular expressions is too complicated, I'll be fine defining the allowed set of characters manually. 回答1: If you don't want to use apache commons, or aren't using Grails, an alternative is: def generator = { String alphabet, int n -> new Random

How to make a random number but it doesn't produce the same number [duplicate]

大憨熊 提交于 2020-01-11 14:35:08
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Random permutation of integers using a random number generator For example I need to make a random number from 1 to 30. But it doesn't produce the same random number. The number produced has to be different one to another. Is that possible? Thanks 回答1: Create a List<Integer> containing 1-30, shuffle it using Collections.shuffle() , then iterate through the list. Of course, at the end of the list, it's impossible

How can I generate different random values in Haskell?

拜拜、爱过 提交于 2020-01-11 13:22:08
问题 Suppose that I have a list like this: let list = ["random", "foo", "random", "bar", "random", "boo"] I want to iterate over a list and map all "random" elements to different random strings: let newList = fmap randomize list print newList -- ["dasidias", "foo", "gasekir", "bar", "nabblip", "boo"] My randomize function looks like this: randomize :: String -> String randomize str = case str of "random" -> randStr _ -> str where randStr = take 10 $ randomRs ('a','z') $ unsafePerformIO newStdGen

Type mismatch: cannot convert from int to int[]

点点圈 提交于 2020-01-11 12:17:07
问题 A question I cannot seem to solve specifically for this line. I have searched for it. The assignment is to implement an application a baseball players Shirt number, batting average and number of walks. Must use a 2-D array of 20 columns and 3 rows. I am working on setting up lines to make the random numbers for the player's Number of times at bat as well as results. Yet I get a error of unable to convert from int to int[]. I have read several other questions with the same problem and none