random

Will time() ever return the same output?

ぃ、小莉子 提交于 2021-01-20 13:20:56
问题 I am generating tokens for users in PHP when they register. I am wondering if two users could ever get the same token... as this will break the system. Please let me know if this is suffiecient. $token = md5(rand().time()); edit: i am now using a generate_uuid() function i found on another question. will this work? function generate_uuid() { return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0x0C2f ) | 0x4000,

Generating identical random numbers in sequence after time seed? (Running on my machine)

我的未来我决定 提交于 2021-01-20 07:51:29
问题 I'm trying to understand precisely why, when called from an external function, my time seeded random number generator returns sequences of identical numbers. Minimal working example of issue: package main import ( "fmt" "math/rand" "time" ) //Generates random int as function of range func getRand(Range int) int { s1 := rand.NewSource(time.Now().UnixNano()) r1 := rand.New(s1) return r1.Intn(Range) } //Print 100 random ints between 0 and 100 func main() { for i := 0; i < 100; i++ { fmt.Print

Generating identical random numbers in sequence after time seed? (Running on my machine)

心已入冬 提交于 2021-01-20 07:51:07
问题 I'm trying to understand precisely why, when called from an external function, my time seeded random number generator returns sequences of identical numbers. Minimal working example of issue: package main import ( "fmt" "math/rand" "time" ) //Generates random int as function of range func getRand(Range int) int { s1 := rand.NewSource(time.Now().UnixNano()) r1 := rand.New(s1) return r1.Intn(Range) } //Print 100 random ints between 0 and 100 func main() { for i := 0; i < 100; i++ { fmt.Print

Can't randomize cards. Some of them are duplicates

萝らか妹 提交于 2021-01-07 06:36:54
问题 I'm new to C, I am trying to randomize 16 cards. In the longer comments I wrote something that I don't have much clear... Btw this is the code: #include <stdio.h> #include <stdlib.h> #include <time.h> #define FACES 4 #define SUITS 4 void shuffle(char *wFace[], char *wSuit[], char *wMixed[][20]); // prototype size_t checker(char *wwMixed[][20], size_t current); // prototype int main(){ char *face[] = {"Jack", "Queen", "King", "Ace"}; char *suit[] = {"Hearts", "Spades", "Diamonds", "Clubs"};

Can't randomize cards. Some of them are duplicates

限于喜欢 提交于 2021-01-07 06:36:41
问题 I'm new to C, I am trying to randomize 16 cards. In the longer comments I wrote something that I don't have much clear... Btw this is the code: #include <stdio.h> #include <stdlib.h> #include <time.h> #define FACES 4 #define SUITS 4 void shuffle(char *wFace[], char *wSuit[], char *wMixed[][20]); // prototype size_t checker(char *wwMixed[][20], size_t current); // prototype int main(){ char *face[] = {"Jack", "Queen", "King", "Ace"}; char *suit[] = {"Hearts", "Spades", "Diamonds", "Clubs"};

How is numpy.random.Generator different from RandomState?

折月煮酒 提交于 2021-01-04 03:30:50
问题 Generator sounds like a replacement for RandomState , and the way of the future for generating random numbers in NumPy. What features or behavior (currently or planned) does Generator have that RandomState doesn't? Both can be parameterized with BitGenerator objects. They have some different methods, but the vast majority appear to be the same. Relevant links: docs on the "legacy" RandomState Generator docs BitGenerator docs Developer's github 来源: https://stackoverflow.com/questions/61352259

How is numpy.random.Generator different from RandomState?

安稳与你 提交于 2021-01-04 03:30:33
问题 Generator sounds like a replacement for RandomState , and the way of the future for generating random numbers in NumPy. What features or behavior (currently or planned) does Generator have that RandomState doesn't? Both can be parameterized with BitGenerator objects. They have some different methods, but the vast majority appear to be the same. Relevant links: docs on the "legacy" RandomState Generator docs BitGenerator docs Developer's github 来源: https://stackoverflow.com/questions/61352259

How is numpy.random.Generator different from RandomState?

丶灬走出姿态 提交于 2021-01-04 03:27:05
问题 Generator sounds like a replacement for RandomState , and the way of the future for generating random numbers in NumPy. What features or behavior (currently or planned) does Generator have that RandomState doesn't? Both can be parameterized with BitGenerator objects. They have some different methods, but the vast majority appear to be the same. Relevant links: docs on the "legacy" RandomState Generator docs BitGenerator docs Developer's github 来源: https://stackoverflow.com/questions/61352259

Fastest precise way to convert a vector of integers into floats between 0 and 1

跟風遠走 提交于 2021-01-02 05:45:38
问题 Consider a randomly generated __m256i vector. Is there a faster precise way to convert them into __m256 vector of floats between 0 (inclusively) and 1 (exclusively) than division by float(1ull<<32) ? Here's what I have tried so far, where iRand is the input and ans is the output: const __m256 fRand = _mm256_cvtepi32_ps(iRand); const __m256 normalized = _mm256_div_ps(fRand, _mm256_set1_ps(float(1ull<<32))); const __m256 ans = _mm256_add_ps(normalized, _mm256_set1_ps(0.5f)); 回答1: The version

How can I draw a random sample from a dataset, proportionate to size, based on different proportions for each value of a factor variable, in R

北城余情 提交于 2021-01-01 17:51:34
问题 I want to draw a random sample from my dataset, using different proportions for each value of a factor variable, as well as using weights stored in some other column. dplyr solution in pipes will be preferred as it can be inserted easily in long code. Let's take the example of iris dataset. Species column is divided into three values 50 rows each. Let's also assume the sample weights are stored in column Sepal.Length . If I have to sample equal proportions (or equal rows) per species, the