35,816 questions
0
votes
0
answers
69
views
Recovering MT19937 state from 24-bit observations to predict 32-bit outputs [closed]
I need to predict Python's random.getrandbits(32) output. I can call a /debug endpoint multiple times to get as many observations as needed, but each observation is only 24 bits.
Then I need to ...
1
vote
1
answer
85
views
What algorithm does Visual Basic 6 use to generate its pseudorandom numbers?
I have legacy code written in Visual Basic 6. It uses Rnd and Randomize to produce an output given an initial random seed. These are the rtcRandomNext and rtcRandomize functions in the MSVBM60.DLL, ...
0
votes
1
answer
101
views
RNG function creating the same sequence despite changes to seed [closed]
I am making an rng function in C with an upper bound. However, I'm always getting the same sequence of numbers - 3675356291. This is the file I'm using:
// The #include block. Contains the header ...
Best practices
1
vote
5
replies
129
views
Predictable random number based on an input string (java)
Given an input string, I want to generate a "random" number between 0 and 1.
However given the same input string, the returned value should stay the same.
I tried something like:
Random ...
4
votes
8
answers
292
views
How to extract a given number of ordered rows from a given number of randomly selected samples?
Starting with the example dat0 below, let's say I want to randomly extract 3 pairs of ìd`s.
Initial data (5 id pairs)
dat0 <-
structure(list(id = c("A", "A", "B", &...
0
votes
1
answer
57
views
TYPO3 tx_news add 'random' to the 'sort by' list setting
In a v12 TYPO3 site running EXT:news 12.3.0 I'd like to display a random selection of news articles, maintaining other chosen restraints (as limit to categories, respect top news etc.).
Best practice ...
2
votes
1
answer
315
views
Does this function result in uniformly distributed integers?
Recently, on a project, I encountered the need for uniformly distributed integers within an arbitrary range [a, b] from random bytes, a problem that is quite common and is usually solved using ...
1
vote
1
answer
125
views
Random stability with non-random object
I have a simple example for random stability in QuestaSim.
module sv_rand_stability;
class dummy;
rand int data;
endclass
initial begin
dummy d;
$display("%...
0
votes
2
answers
112
views
How to create test cases in Polygon for Python program with random values?
I have a beginner Python program that generates random output and does not take any input. For example, it simulates rolling a dice 5 times and prints the results, their sum, and average:
import ...
1
vote
1
answer
106
views
Randomness instructions vs syscalls [closed]
I've been digging into "true" randomness idea, and I've noticed that modern CPUs support instructions for generating randomness. X64 has RDRAND instruction, while ARM has RNDR (I'm not ...
0
votes
0
answers
82
views
Coordinates satisfied conditions are outside of the expected area
I have the following code to calculate and visualise the probability of scoring 10 points or more
This is the Scoreboard image that I used to run the code
from PIL import Image, ImageDraw
import ...
0
votes
0
answers
67
views
WordPress REST API orderby=rand parameter not working - returns same posts instead of random
I'm trying to fetch random posts using the WordPress REST API, but the orderby=rand parameter is not working as expected. Instead of returning random posts on each request, it
consistently returns the ...
4
votes
3
answers
169
views
Generator that yields True a fixed number of times at random intervals before exhausting
I want to iterate through a list of size n, with A 1s in it (the rest are 0s), and I want the 1s randomly distributed.
n and A are large, so I'm trying to make a generator instead of a list.
If they ...
6
votes
3
answers
261
views
How can I generate a random integer not divisible by p OR q
I need to generate a random integer from 0 (inclusive, but it doesn't matter) to p*q (exclusive, but it doesn't matter) that is divisible by neither p nor q. It just so happens that p and q are ...
-6
votes
2
answers
198
views
How to reorder numbers in a set in Python so that the set's numbers are increasing? [closed]
I'm trying to reorder the randomly generated numbers of a set, and I don't know how to do so:
import numpy as np
import random as rd
NUMBER=5
c = np.zeros(NUMBER+1)
for k in range(1,NUMBER+1):
...
2
votes
1
answer
149
views
In Rust is it possible to use a pseudo random number generator with a seed in a const context?
I'm writing a chess engine in Rust and want to start using Zobrist Hashing, which requires me to pre-initialize an array of pseudo-random numbers from a constant seed.
Since this array won't change, I ...
0
votes
1
answer
132
views
Why is my code only assigning a certain variable sometimes, rather than everytime the program runs? [closed]
I am working on a small hobby project where I try to create a government for a fictional world. So starting out, I have an assembly of 250 people, with many different details that are being generated ...
4
votes
2
answers
183
views
C How to generate an arbitrary permutation within range [i,j]? [closed]
Does C standard library provide any function that generate a random permutation of consecutive numbers within a range?
How to make a function that efficiently does it? I'm thinking of making a random ...
-1
votes
1
answer
190
views
Get random rows in interval in T-SQL
I need to select 10 to 20 random rows from a table. (I only can find how to select just N random rows). I need to get something like this
SELECT *
FROM table
WHERE ABS(CHECKSUM(NewId())) % 19 BETWEEN ...
0
votes
0
answers
73
views
nodename nor servname provided – Error when connecting to MITM proxy from Packet Tunnel (Network Extension on macOS)
I'm building a Data Loss Prevention (DLP) tool using a Packet Tunnel Provider on macOS with the NetworkExtension framework. The tunnel sets up proxy settings to redirect HTTP and HTTPS traffic through ...
2
votes
1
answer
87
views
np.random() is getting treated as module [closed]
I am trying to create a random numpy array using np.random() but for some reason, instead of taking it as a function, google collab is taking it as a module, I checked the documentation, but I would ...
1
vote
1
answer
52
views
How to introduce seed in np.random.random?
I need to create a number of points in a square [0,1]x[0,1].
To obtain an array of coordinates, I used:
N_fixed_points = 10
selection = np.random.random((N_fixed_points,2))
which gives me a proper ...
0
votes
2
answers
75
views
How to repeatedly sample so that the sampling result doesn't change?
I have an array from which I want to select a number of rows, so that the rows selected don't vary if I repeat the sampling process.
In my following code, this is not the case; each time I run the ...
2
votes
2
answers
75
views
Select randomly stratified sample from Pandas dataframe
I have created the following pandas dataframe:
import pandas as pd
import numpy as np
ds = {'id':[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26],
"Grade":["...
10
votes
1
answer
178
views
How to correctly determine the seed type for the various random number engines in the c++ standard library
Recently there was a discussion on the reddit c++ subedit pertaining to the difficulties of using the random library. One of the issues was how to correctly seed a random number engines.
std::...
2
votes
2
answers
167
views
How to fill an existing numpy array with random normally distributed numbers
I would like to generate many batches of random numbers. I only need access to one batch at a time. Naively, I could repeatedly call np.random.randn(size), but that allocates an array each time. For ...
-1
votes
1
answer
68
views
Explain random selection of cons-ed weighted nodes
In Scheme (extempore version) I sometimes use expressions similar to the following
to choose alternative defined callback nodes.
(random (cons 0.1 'node1) (cons 0.2 'node2) (cons 0.7 'node3))
This ...
2
votes
1
answer
130
views
Generate Single Column Random Number Array based on Cell Value
I have a working formula that I found in the internet {credit to owner} that needs a little tweaking to suit my need. The formula is currently working to provide random numbers based on the following ...
1
vote
1
answer
117
views
In Rust, why can't you call random_range with a reference?
Let's say I have a function that shall generate two random values inside a given range:
fn gen_two_numbers(range: Range<u32>) -> (u32, u32) {
...
}
I tried to implement it like this:
fn ...
2
votes
1
answer
129
views
Is True RNG possible in python?
As i seen, True RNG (TRNG) in a software-only program is impossible. Modern CPUs not providing TRNG to your software. For example, Intel CPUs starting from Ivy Bridge 3rd generation supports RDRND ...
1
vote
2
answers
183
views
How to sample a range of Excel values (i.e. one column) to pick 100 random values
I have a column of 1,800 distinct values in Excel.
I want to randomly sample 100 of them.
What's the Excel way to do it?
I looked here and use the approach described there:
=INDEX($A$2:$A$10,...
0
votes
1
answer
109
views
I need help for making a dice game with assembly language
I'm trying to make a simple dice game using assembly language (MASM).
The program generates two random numbers (1~6) and compares them.
If the player's number is higher, it prints "You Win!",...
0
votes
1
answer
72
views
Postgres SELECT query randomness
The following statement uses random() to produce two distinct values:
select random(), random();
But the next statement outputs two equal values:
select random(), random() order by random();
...
3
votes
1
answer
237
views
How do I convert a random uint32_t into a random float in the interval [0, 1) using the method from Xoshiro documentation?
On the Xoshiro webpage, they have the following statement under the heading "Generating uniform doubles in the unit interval":
A standard double (64-bit) floating-point number in IEEE ...
1
vote
2
answers
88
views
Working of kotlin random generator across multiple environments
I'm using Kotlin's default random generator to obtain a float between 0 and 1, which I am using to execute a task for a x% of requests. The Random.nextFloat() call happens only once per Lambda ...
1
vote
1
answer
100
views
Random sample with multi-variate conditions
I have a dataset that I need to pull a random sample from. This is the data:
{'character': {0: 'mario',
1: 'luigi',
2: 'yoshi',
3: 'peach',
4: 'bowser',
5: 'boo',
6: 'toad',
7: 'lakitu',
...
2
votes
0
answers
123
views
Parallel Random Number Generation in GIL-Free Python
I am doing a reinforcement learning simulation in Python that involves running many episodes and updating the weights of the agent per episode. To speed up the process, I wish to run parallel ...
1
vote
0
answers
106
views
Understanding the Unexpected Behavior of Random Number Generation in a Binary-Based Function
I wrote a function in Arduino to generate random numbers with the same number of binary bits as the input. However, when using random() with calculated ranges, the output sometimes doesn't match the ...
2
votes
0
answers
127
views
How to set a seed for gen_random_uuid()?
For testing purposes on a table like this:
CREATE TABLE my_table (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
.
.
...I would like to get the same id's on each test run to better ...
4
votes
3
answers
170
views
how to generate random probability arrays with pre specified mean
I have a pre specified mean [0.5, 0.5, 0]. This is a probability array which sum up to 1.
I want to generate several, say 10 random probability arrays (each sums up to 1) whose mean is [0.5, 0.5, 0], ...
0
votes
1
answer
219
views
pick n different random samples from subgroup
I have two Dataframes that look like this:
df = pd.DataFrame({'PERSONALNUMMER': {4756: '0209740',4820: '0234212',4855: '0251297',4750: '0209326',4992: '4000404'},
'MANDANT': {4756: 'OM', 4820: 'OM', ...
1
vote
3
answers
184
views
Calculating the area of a plot in R [closed]
I need help coming up with an efficient algorithm that calculates the limits of the area of a rectangle in R based on the proportion of points that fall into it. Let me start with some example data.
...
0
votes
1
answer
57
views
How do I shuffle randomly the output of csv,DictReader so that I am able to operations on each values using ThreadPoolExecutor
I am trying to use ThreadPoolExecutor with 8 workers on a csv file data. When I read the csv file using csv.DictReader, I get a dictionaries with header as a key and each row having the value.
Now ...
1
vote
2
answers
167
views
CUDA: curand_uniform() distribution not as random as expected
My goal is to use curand_uniform() to have every kernel thread generate a single random number. I am testing the randomness my program generates by treating each generated numbers as an index into a ...
2
votes
5
answers
114
views
Create an N length list by uniformly (in frequency) selecting items from a separate list in python
SETUP
I have a list days and a value N
days = ['Monday','Tuesday','Wednesday','Thursday','Friday']
N = 52
WHAT I AM TRYING TO DO
I am trying to create a list selections with length N where I ...
0
votes
0
answers
98
views
Best practice for function-level reproducibility of random number generation with NumPy
I am aware of suggested best practices for random number generation in NumPy, which basically boil down to:
Use the new API, via np.random.default_rng and related functions; and
Set a seed at the ...
8
votes
4
answers
387
views
Generate 4 random numbers between -1.0 and 1.0 such their sum is 1 using python
I am trying generate 4 random numbers between -1.0 and 1.0 such that their sum is 1 using python.
I initially looked at the dirichlet function in numpy but that only works for positive numbers.
One ...
1
vote
3
answers
152
views
Scraping the correct postcodes data in python
I have only been using python for a few months and I am trying to blend my hobby (skating all the london postcodes) with learning to code.
I found the following data
https://github.com/radiac/UK-...
-1
votes
1
answer
115
views
Comparing numpy versus scipy when sampling random values from a poisson distribution [closed]
I am generating random samples from both numpy and scipy for a Poisson distribution, but it appears that scipy never produces values of x=0. Scipy seems to be off by x=1, i.e., it is shifted to the ...
7
votes
0
answers
332
views
Is there a compelling reason to use "old" RNGs instead of std::philox_engine?
P2075R6 has been accepted into the C++26 standard.
It provides the std::philox_engine class template, and the std::philox4x32 and std::philox4x64 aliases with reasonable constants.
The proposal ...