# Questions tagged [random]

This tag is for questions pertaining to random numbers and their generators, whether pseudo-random or truly random.

27,897
questions

**-3**

votes

**0**answers

17 views

### Black jack but #TypeError: 'type' object is not subscriptable [on hold]

I'm trying to do a black jack game like this (one part of it) but i have no idea of making it work)
A = 1
J = 10
Q = 10
K = 10
hand = 0
deck = [
1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, ...

**1**

vote

**1**answer

20 views

### adding up random ints in a JSON file with Python

here is my code:
#start.py
import json
y = {}
y['red'] = {'name': "red", 'p': 0, 'rand': 0}
y['blue'] = {'name': "blue", 'p': 0, 'rand': 0}
y['green'] = {'name': "green", 'p': 0, 'rand': 0}
with ...

**1**

vote

**2**answers

23 views

### Easy way to compare random results and convert them into “points” on a JSON file in Python

Here is a simplified version of my code:
import json
import random
y = {}
y['red'] = {'name': "red", 'p': 0}
y['blue'] = {'name': "blue", 'p': 0}
y['green'] = {'name': "green", 'p': 0}
with open('y....

**0**

votes

**1**answer

41 views

### Using Pandas data frame how to randomly select row data using multiple conditions

I have a data set with column NDVI , Lat , Long, Group, Village & Taluka.
I want to randomly select 10 villages in each taluka,and each 10 villages select 5 row data randomly. but I am stuck to ...

**1**

vote

**6**answers

105 views

### Weighted Random Number generator with updates

My question is an extension of this question: Weighted random numbers
I'm trying to implement a weighted random numbers. I'm currently just
banging my head against the wall and cannot figure this ...

**1**

vote

**2**answers

52 views

### Is there a better way to have my computer opponent to generate a word of (3 > random length <= 7)?

I have implemented the following method to do as such, but I still find that a lot of the times it produces only a three letter word. Once in a great while, it does do a four letter, five letter, etc. ...

**-3**

votes

**0**answers

41 views

### Random Number without duplicate [duplicate]

I want to generate a random numbers and view them in textbox without duplicate, so each time I click on the
button, it should show a unique number. Any ideas how can I do that please?
here is my Code:...

**0**

votes

**1**answer

27 views

### How secure would it be to choose a random number based on time?

If I had an online room of 10 users arriving at different times and I wanted to pick up a random user once the room is full, would it be secure to select the user by using the timestamp of when the ...

**0**

votes

**1**answer

25 views

### Python: Randomly select a subgroup in a group

I have a dataframe that looks like:
patient_id note_id lines
A 10 1
A 10 2
A 10 3
A 29 1
A 29 ...

**0**

votes

**0**answers

23 views

### KMeans not returning reproducible results in sklearn, even fixing random_state

The following code tests KMeans for several n_clusters and tries to find the "best" n_clusters by the inertia criterion. However, it is not reproducible: even fixing random_state, every time I call ...

**4**

votes

**2**answers

66 views

### Java Math.random closed double interval

How do I generate random double values in a closed interval [x;y] in Java, e.g [0;10]? The API of Math.random() says it returns values in [0;1), so multiplying by 10 does not help (as well as ...

**-3**

votes

**1**answer

46 views

### Why random is giving wrong output

I wrote a program for math game which calculates score based on right answers. It will ask the user twice for the answer of a given question, if its correct it will add 10. However the score is not ...

**-1**

votes

**0**answers

12 views

### random deaths in python game [on hold]

full code is here: https://repl.it/repls/UnevenLovingDecagons
On the end of the loop I'd like to create situation where each few years half of colony dies. But I don't want it to happen on regular ...

**0**

votes

**0**answers

15 views

### randomly distribute nodes in groups and calculate the probability distribution of nodes number in every group

Suppose there are 10000 nodes and 10 groups. I can first randomly distribute all nodes in 10 groups randomly and count the node numbers in every group:
for j=1:10
for i=1:10
N=10000;% the whole ...

**0**

votes

**5**answers

63 views

### Need to generate random numbers between two values ignoring the given values

I need to generate random numbers using Math.random() between two given values but ignoring on this comparation the two given values or just one depending the case.
Those are the values to do:
...

**0**

votes

**0**answers

12 views

### What is an alternative method of using random.choices() in python 3.5

Since, random.choices() is not available in python 3.5, is there any alternative method for this function?

**0**

votes

**1**answer

76 views

### Segmentation fault with std::uniform_int_distribution

EDIT EDIT: A minimal reproducible example worked fine, in the end, I resolved the problem by carefully rebuilding my program. Doing so, I found a wrong access of an std::vector, which was probably one ...

**-1**

votes

**0**answers

33 views

### python - problem with loop taking info from outside of loop [on hold]

It is my first post here
Please see my code: https://repl.it/repls/UnevenLovingDecagons it is a game called Namiestnik which originally was on C64 and it was text economic strategy game, but I try ...

**0**

votes

**2**answers

40 views

### Android: Set Random background color for textview on create

I want is when I load my app up it to randomly have a certain colored background for each textview from a predefined list of strings.
@Override
protected void onCreate(Bundle savedInstanceState) {
...

**0**

votes

**0**answers

24 views

### How to generate a 3D grid with (many) unique values which are equal for each user but shifted by a seed and hard to predict?

Basic idea:
Looking for about 10^12 unique values which lie in a grid of about 100k x 100k x 100k and can be shifted by the position of one of those values.
In 2D it would look like:
_
_
Each ...

**1**

vote

**1**answer

32 views

### Random sampling based on vector with multiple conditions R

I have a large dataframe SYN_data with 150000 rows and 3 columns named SNP, Gene and count.There is a list r with 2545 count values that also include some duplicates. Now I need to randomly sample ...

**0**

votes

**1**answer

35 views

### How to use the PRNG linear congruential generator for rolling one dice in Matlab

I have to design a linear congruential generator for rolling one dice in Matlab. The general equation I use is defined by the recurrence relation:
where a,b en c are large and positive values.
The ...

**-1**

votes

**0**answers

19 views

### Generate double numbers between lowerBound and upperBound, with the value upperBound inclusive

I use the method:
public static double GenerateRandomDoubleValueBetweenLowerBoundAndUpperBound(double lowerBound,
double ...

**0**

votes

**2**answers

26 views

### Output of shuffling a string is printed on 2 lines of output

I've decide to practice solving anagrams, something I'm very bad at. I got 1000 most common words of English language, filtered those under 5 letters and over 9 and then wrote a simple script:
import ...

**0**

votes

**4**answers

56 views

### Convert random numbers with a specific range in a date

I'm trying to read in random numbers and convert them into a date. I tried doing it for a first number using java.util.date and ThreadLocalRandom. It say's 'The local variable d1 may not have been ...

**1**

vote

**1**answer

20 views

### How to “stash” random state generator state

I'm seeding a random number generator for reproducible results with:
import random
SEED = 32412542
random.seed(SEED)
I'd like to make it return "non-reproducible" random values for only one part of ...

**-1**

votes

**0**answers

20 views

### How to generate an array with random numbers? [duplicate]

I am trying to print out an array with random numbers, but I'm getting a Arrayoutofbounds Exception.
public class feld{
static int [] getRandomField(int size, int limit){
int[] array=new ...

**-1**

votes

**0**answers

26 views

### How to set the seed value in python to a specific number for my rancom number generator

import statistics as stat
from statistics import mean
from random import seed, choice
from math import hypot
import random
from turtle import *
seed(20190101)
for i in range(100):
i = random....

**0**

votes

**1**answer

30 views

### The method of retrieving a list of data in firebase using random generate key? Thanks

My Database Structure:
Hi,I'm currently working on Android Studio project. How do I retrieve a list of data in firebase with random generate key? For example, I need to retrieve the institute name, ...

**-1**

votes

**1**answer

20 views

### How can i get 3 random numbers as output from a list in python?

Example i have a 10 items list like below,
test_list = [1, 4, 5, 2, 7, 3, 6, 8, 9, 10]
so my question is how can i get 3 random numbers as output, is there any way to get it?

**0**

votes

**2**answers

36 views

### How to find the frequency of second histogram based on quantile of first

I have two sets of data. In the first set I can calculate the 25th percentile and output the x value. I would then like to take that x value to a second data set and determine the frequency and ...

**0**

votes

**1**answer

33 views

### Program printing different co ordinates from the ones I generated for it

Basically I need my program to place points I type in manually on a grid (which it does fine) and then place a point randomly on the same grid and repeat for as many times as user requests. Currently, ...

**1**

vote

**0**answers

48 views

### performance issue with std::normal_distribution?

One of the classes I use has a data member that is a std::vector of about 12 million numbers (float or double). If I just read it from file and write it, that takes much less than a second. But if I ...

**0**

votes

**0**answers

19 views

### Randomly generate paths with a given length and surface coverage

I am working on a tower defense style game where I want to randomly generate the paths based on given criteria - specifically the length of the path and, if possible, how much it doubles back/stays in ...

**-1**

votes

**0**answers

49 views

### C programming - A array and a random number?

I'm trying to get a random number between 0 and 1000000 in a C language program, but when I run my program it returns me a number 0.00000 and I want a number between 0 and 1000000.
Here's the code
#...

**1**

vote

**1**answer

28 views

### How do I ask the Imgur API for a random image by tag?

Currently I am trying to find out, if you can ask for pictures by a given tag. Reason is, I am doing a discord-bot via Node.js where people can do commands that will need a random picture, gif by a ...

**-1**

votes

**2**answers

52 views

### How to divide data frame in r in groups of equal number of records and split dat randomly & equally in two data frames

I have some data that contains about 30000 records. I want to divide the data into groups of 288 records. And then sort the data into test_data & train_data separate data frames where first 4 ...

**1**

vote

**1**answer

31 views

### Numpy: random seed and multithreading causes differing results

Tested on python 3.7, numpy 1.17.3:
it seems, that the random number generation with numpy when using a fixed seed and multithreading is not providing consistent results.
This issue does not come up ...

**0**

votes

**3**answers

55 views

### Generating random array of fixed length (Java)

im just looking to change my code so that a random array of a fixed length of 100 integers is generated every time the code is ran rather than just have a pre-set array within the code. Im quite new ...

**-1**

votes

**1**answer

26 views

### Something wrong happens when shuffle a tensor

I am trying to shuffle a tensor, but I find there is something wrong when tryting to using random.shuffle(),here is my code:
import numpy as np
import torch
import random
if __name__ == '__main__':
...

**0**

votes

**0**answers

25 views

### i want to convert randint () of python in sequincial form

i want to know which function to use get sequence form of data , how i can replace randint () used in code
enter code here
fig = plot.figure(figsize=(30, 30))
outer = gridspec.GridSpec(5, 5, wspace=...

**-1**

votes

**0**answers

16 views

### What is a rotation matrix, anyone know the answer to this question?

Question: Create a first function that fills a 1X2 vector with two random values between 1 and 100, Create a second function that takes this vector and rotates it by a parameter angle.
formulas: ...

**0**

votes

**2**answers

50 views

### Rand() isn't displaying random number, please help me understand what's wrong :) [duplicate]

So I am new to C++ and learning all alone... until now everything went fine, but i am learning how to use rand() and the result does bother me a little...
So my goal is to generate a random number ...

**0**

votes

**1**answer

21 views

### How use a random key in json in multidimensional array

I need get random key to select different response.
I have: response.data.players["11"].name and i need random value instead of 11 because all keys are numbers.

**3**

votes

**1**answer

42 views

### How to generate a random normal distribution having mean 11.7 (in Python)

I need to generate an array of 108 values following a normal distribution having mean= 11.7 and being the minimum value of the distribution 3.4, while the maximum value is 46.
I tried using s = np....

**1**

vote

**2**answers

68 views

### C# Generate 5 random times between 08:20:00 and 08:29:59

I'm needing to generate 5 random times between 08:20:00 and 08:29:59.
These times need to be added into the top text boxes from left to right.
I'm currently doing it with this code:
private void ...

**-3**

votes

**1**answer

54 views

### Random x and y position

Only thing i want is to pick a random X position and random Y position
Random x = new Random(255);
Random y = new Random(255);
int xp = x.Next(0, 255);
int yp = y.Next(0,255);
compile time Error:
...

**2**

votes

**3**answers

55 views

### Random number generator returns same result upon creation of new object

I am currently teaching myself java, and one of the practice problem's final output needs different name for different objects (which is decided based on random number generator). However, every time ...

**2**

votes

**2**answers

43 views

### SPSS Randomly select a number from a respondent's input

I'm hoping there is SPSS syntax that I can use to randomly select a number from among a couple of variables. For example: the data lists the ages of respondent's children in four variables - Age1 Age2 ...

**0**

votes

**1**answer

15 views

### Ramdomize selected column in Excel

I am new to this formula stuffs in excel. After searched on the internet I found this =RAND() function which I am using to randomize a couple of numbers. Like the one on the image.
By default, ...