random

Python - Generate random dates to create Gantt sequenced tasks

我是研究僧i 提交于 2021-02-04 21:01:06
问题 The idea is to generate random but sequenced dates based on workload estimation in python. The goal is to have an output like this: Task , Start_date , End_date task1, 01/06/2020, 05/06/2020 task2, 08/06/2020, 11/06/2020 task3, 12/06/2020, 24/06/2020 ... So I started to work on this code but unable to find a way to randomize it. #startdate start_date = datetime.date(2020, 1, 1) #enddate end_date = datetime.date(2020, 2, 1) time_between_dates = end_date - start_date days_between_dates = time

PHP - how to echo random lines from txt file?

梦想的初衷 提交于 2021-02-04 21:01:05
问题 I want to echo random lines by PHP from file sitemap.txt that provide as: link1 link2 link3 link4 ... link10000 I have tried using this function: $lines = file("sitemap.txt"); $data[link] = $lines[array_rand($lines)]; But this $data[link] will echo output 1 random value only such as link1 or link10000 However, I need to echo 100 random values from sitemap.txt How can I optimize this function? Thanks 回答1: $lines = file("sitemap.txt"); $data = array_rand($lines, 100); foreach($data as $value) {

Python - Generate random dates to create Gantt sequenced tasks

感情迁移 提交于 2021-02-04 21:00:00
问题 The idea is to generate random but sequenced dates based on workload estimation in python. The goal is to have an output like this: Task , Start_date , End_date task1, 01/06/2020, 05/06/2020 task2, 08/06/2020, 11/06/2020 task3, 12/06/2020, 24/06/2020 ... So I started to work on this code but unable to find a way to randomize it. #startdate start_date = datetime.date(2020, 1, 1) #enddate end_date = datetime.date(2020, 2, 1) time_between_dates = end_date - start_date days_between_dates = time

Javascript random number with weighted probability

三世轮回 提交于 2021-02-04 19:12:25
问题 I'm trying to create a function with the following signature: function weightedRandom (target, probability) { // calculate weighted random number that is more likely to be near target value return value; // number from 0 to 1 } It should do the following: Generate random number from 0 to 1, but not including 1 The probability of any given number being picked in that range is NOT evenly distributed There is a greater chance that the number picked is near the target value (target is also a

Generating random string of seedable data

末鹿安然 提交于 2021-02-04 18:14:48
问题 I'm looking for a way to generate a random string of n bytes in Python in a similar way to os.urandom() method except providing a way to seed the data generation. So far I have: def genRandData(size): buf = chr(random.randint(0,255)) for i in range(size-1): buf = buf + chr(random.randint(0,255)) return str(buf) However this function is very slow, generating a megabyte of data takes about 1.8 seconds on my machine. Is there any way of improving this (or alternatively a way to seed os.urandom).

Why is PHP selecting the Random Values like that?

∥☆過路亽.° 提交于 2021-02-04 17:26:05
问题 So... I was testing something and noticed that when I run this code: $arr = str_split("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890", 1); print_r(implode(array_rand(array_flip($arr), 16))); The Output is Refresh 1: BDFIJKPTVkl12789 Refresh 2: HIJKMQWYdfmorsw3 Refresh 3: FGHMNRVYfhknouw5 Refresh 4: AFIJKRSVeiuwx579 Refresh 5: DJORYZcgijlpqry1 Refresh 6: EISWbhjmoqr45689 Refresh 7: CDEFOTXdhkloqr27 Refresh 8: AEFIKLNORSknx349 Refresh 9: DEFHJMTVZcgpstz0 Refresh 10:

Generation sample using kernel density estimates in r

社会主义新天地 提交于 2021-02-04 16:34:05
问题 I need generate sample from existing data using kernel density estimates in R. In my data missing negative values (and can not be), but in generate sample negative values present. library(ks) set.seed(1) par(mfrow=c(2,1)) x<-rlnorm(100) hist(x, col="red", freq=F) y <- rkde(fhat=kde(x=x, h=hpi(x)), n=100) hist(y, col="green", freq=F) How to limit the range of the KDE and generated sample? 回答1: rkde pas a positive argument: y <- rkde( fhat = kde(x=x, h=hpi(x)), n = 100, positive = TRUE ) An

Does Python have a function to mimic the sequence of C's rand()?

两盒软妹~` 提交于 2021-02-04 08:24:09
问题 I am looking for a Python function that will mimic the behavior of rand() (and srand()) in c with the following requirements: I can provide the same epoch time into the Python equivalent of srand() to seed the function The equivalent of rand()%256 should result in the same char value as in c if both were provided the same seed. So far, I have considered both the random library and numpy's random library. Instead of providing a random number from 0 to 32767 as C does though both yield a

Random non overlapping circles(with circle number controlled) in python and pygame

痴心易碎 提交于 2021-02-02 09:52:32
问题 I was writing the code for non overlapping random circles with different radii.I kind of got the deserved, but my 'if' statement that checks overlap or non overlap excludes a number of circles. So, I get lesser number of circles. Here's the code: import pygame import numpy as np pygame.init() display_width = 800 display_height = 500 black = [0, 0, 0] white = [255, 255, 255] red = [255, 0, 0] display_surface = pygame.display.set_mode((display_width, display_height)) clock = pygame.time.Clock()

How predictable is the result of rand() between individual systems?

我与影子孤独终老i 提交于 2021-02-02 02:20:18
问题 I plan to create a challenge which will involve predictable randomness. I understand that for a given system, if srand() is seeded using the same value, rand() will return a predictable sequence of results. However I’m not sure to what extent this sequence is consistent between different systems. Will the result be the same as long as the compiler uses the same implementation? Or will the same program on two different systems yield different results? 回答1: A random number generator (RNG) is