random

Emulate C# Random() in C++ (Same Numbers)

房东的猫 提交于 2020-01-14 09:43:12
问题 Is there a way to implement the C# Random() class in C++? I specifically need to generate the same number sequences based on a given seed. The scenario: I am working to "break" several encrypting malware by exploiting their usage of Random() in C# to generate the key. Obviously this is weak to having only 2^32 possible keys, ~4.3B keys, which is in the realm of possibility to guess. I have written bruteforcers in C#, but they are rather slow, no matter how much I optimize. I would like to

evenly distributed random numbers

时光总嘲笑我的痴心妄想 提交于 2020-01-14 09:33:06
问题 Hey, is there way to choose evenly distributed random numbers? I used this function Math.floor(Math.random()*2) which returns either 1 or 0. However, I dont think it has exact 50% chance to produce either one. Better thoughts? Thank you 回答1: If you do not believe, check: <script type="text/javascript"> var total = 0; var ones = 0; for (var i = 0; i < 100000; i++, total++) { ones += Math.floor(Math.random()*2); } alert(ones/total); </script> This code gives me 0.49972 - very close to 50%. 回答2:

What is the standard way to get the state of a C++0x random number generator?

给你一囗甜甜゛ 提交于 2020-01-14 08:57:25
问题 I am trying to learn the new C++0x approach to random number generators (26.5), and implement at C++0x-compliant random number engine (26.5.1.4). The standard goes into detail on the required interface for seed sequences, and how they can be passed to the constructor or seed functions of engines. However, I cannot find any standard interface to create or generate a seed sequence from an engine, thereby getting its internal state. Is there one? Or can states only be copied between engines via

printing out 1 random letter of a word php functions [duplicate]

[亡魂溺海] 提交于 2020-01-14 06:29:10
问题 This question already has answers here : a method of selecting random characters from given string (15 answers) Closed 5 years ago . i want to Use strlen(), substr(), and rand() to print a random character from my name to the screen. <html> <p> <?php // Use strlen(), substr(), and rand() to // print a random character from my name to the screen. $name = "jordi"; $length = strlen("$name"); $length = rand(); $partial = substr($lengt, 0,5); print $name. "<br />"; print $length. "<br />"; print

Generate different random numbers

吃可爱长大的小学妹 提交于 2020-01-14 03:16:09
问题 I want to generate different random numbers . I used srand and rand , but in my output some numbers are identical . This is my output : How to do with srand to generate different numbers ? #include<iostream> #include<time.h> #include <windows.h> int main(){ time_t t; std::vector<int> myVector; srand((unsigned)time(NULL)); for (int i = 0; i < 40; i++){ int b = rand() % 100; myVector.push_back(b); std::cout << myVector[i] << std::endl; } Sleep(50000); } 回答1: One easy way is to add all numbers

shell练习题

雨燕双飞 提交于 2020-01-14 00:19:40
计算器 calc.sh #!/bin/bash echo " $* = $(( $ * )) " 比较整数大小 #!/bin/bash read -a num -p "请输入两个整数: " [ ${#num[*]} -eq 2 ] || { echo "参数不是两个" exit 5 } [ [ " ${num[0]} " = ~ ^ [ 0-9 ] +$ ] ] || { echo " ${num[0]} 不是数字" exit 1 } [ [ " ${num[1]} " = ~ ^ [ 0-9 ] +$ ] ] || { echo " ${num[1]} 不是数字" exit 2 } if [ ${num[0]} -gt ${num[1]} ] ; then echo " ${num[0]} > ${num[1]} " elif [ ${num[0]} -eq ${num[1]} ] ; then echo " ${num[0]} = ${num[1]} " else echo " ${num[0]} < ${num[1]} " fi 判断输入是整数 function isnum ( ) { NUM = $1 if [ [ $NUM = ~ ^ [ 0-9 ] +$ ] ] ; then echo $NUM is num else echo $NUM is not num fi }

How can i make a “dice” that randomly generates a number 1-6 EACH time it is used?

☆樱花仙子☆ 提交于 2020-01-13 20:22:29
问题 Right now i am using int die = (int)(6.0 * Math.random()) + 1; This does not work for the loop i am trying to create. This is the method i am using. public void computerRoll() { do { roll(); System.out.println("Roll:"+ die); computerScore += die; } while (computerScore <= 20 && die >=2 && die <=6 ); if (computerScore >=20) computerHold(); if (die == 1) switchTurn(); } The roll() method just simply has the previous line of code in it, "int die = (int)(6.0 * Math.random()) + 1;" i have tried

How can i make a “dice” that randomly generates a number 1-6 EACH time it is used?

不问归期 提交于 2020-01-13 20:20:38
问题 Right now i am using int die = (int)(6.0 * Math.random()) + 1; This does not work for the loop i am trying to create. This is the method i am using. public void computerRoll() { do { roll(); System.out.println("Roll:"+ die); computerScore += die; } while (computerScore <= 20 && die >=2 && die <=6 ); if (computerScore >=20) computerHold(); if (die == 1) switchTurn(); } The roll() method just simply has the previous line of code in it, "int die = (int)(6.0 * Math.random()) + 1;" i have tried

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

北慕城南 提交于 2020-01-13 12:07:23
问题 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

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

安稳与你 提交于 2020-01-13 12:04:15
问题 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