# Questions tagged [random]

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

25,588 questions
22 views

### Generate random numbers with 3 to 7 digits in R

How can I generate random numbers of varying length, say between 3 to 7 digits with equal probability. At the end I would like the code to come up with a 3 to 7 digit number (with equal probability) ...
6 views

### Generating a Random Variable that does not overlap with previous ones while placing components

I'm randomly placing components on a grid using random variables in Python, with the following line of code repeated for the no of components to be placed: [random.randint(0,32), random.randint(0,27),...
25 views

### Python 3 ball drop histogram

I have to make a code that drop balls each of which will bounce randomly and land in a slot. There will be 21 slots (numbered from -10 to 10). Each ball will be dropped over the middle slot (number 0)...
16 views

### How to obtain the p-value of random variable in a lme4 mixed model?

I use lme4 in R to fit the mixed model model<- glmer(responcevariable~ fixedvariable1 + fixedvariable2 +fixedvariable3 + fixedvariable+ (1|randomvariable1)+ (1|randomvariable2)+(1|...
26 views

### random non-number assignment without duplicates using arrays

I'm trying to create a program that assigns a random, unique color to a piece of clothing. I use an array to store already picked colors and try (with for and while) to eliminate duplicate colors. I ...
40 views

### Simple C random lottery number

I would like to generate 5 different numbers in the simplest way and put them into an array. Something is wrong with my way of thinking, could you please correct my code? void lottery(int *array){ ...
77 views

### Class member is being changed unexpectedly [on hold]

I'm making a dice of the Royal Game of Ur in C#. It needs 4 4-sided pyramids that have 2 out of 4 peaks colored white. This means that a single dice gives 50/50 chance of being either 0 or 1. Now ...
42 views

### What is the most efficient way to create randomness in PHP [duplicate]

So i was thinking about that what is the most efficient way to create randomness in PHP. I want to create key that is generated randomly by PHP. Now i have been testing few functions example ...
23 views

### If you have several arrays, how can you randomly choose one of the several arrays?

I'm currently doing a project relating to a music playlist and I need to be able to print the first letter of a specific artist and song for the user to guess however the artist and song must be ...
22 views

### Pseudo random number

I need to find a function f(t) which generates pseudo random numbers in range [0;1) with uniform distribution. Results for same t must be equals.
23 views

### Issue while generating unique alphabets in PHP

Am trying to generate a unique value in PHP where the first and last letters should be J and 1 respectively while the middle characters should be a series of aplhabetical letters and the whole value ...
104 views

### How to return the largest integer in an Array that has 10 random integers in it?

So this is a coding question from school I have, I don't want to say "hey guys do my homework for me!", I actually want to understand what's going on here. We just started on arrays and they kind of ...
48 views

### Ambiguous type error & Multiple different random values in the same function

I need multiple random numbers in different ranges (which could be avoided by multiplying the result of the random number generator with a constant). I'm making an Asteroid clone in Haskell, and I ...
20 views

### How do I rotate links in a list of links once each day in Php

PHP question... I have a list of 10 links that I want to rotate the order of, once each day so that: Day 1 echos Link 1, Link 2, Link 3, etc. Day 2 echos Link 2, Link3, Link 4, etc. Day 3 echos Link ...
32 views

### Unity: Get a random value from a probability distribution

I would like to get a random value from a von Mises distribution using the Accord.NET framework for statistics. It should return a float between -pi and pi, where it's most likely to return values ...
49 views

### C# Checking if there is same random value in the array or not

I want to check if there is same value in the array or not as I mentioned in the title. And if there is, I want to pass that value and check another random value to add to listbox. In my form, there ...
15 views

### Generating Random Graph in R with Prescribed Degree Distribution

does anyone know how I can generate a random graph with prescribed degree distribution(for example Poisson) in R? Is there any package that can help? Thanks in advance.
58 views

### How to randomly replace a specific element in a nested list?

I have a list of lists. How do I create a function which randomly replaces an instance of 10 with another number? lst = [ [10, 100, 10 ], [10, 1000, 10], [100, 100000, 100], [10, 10, 0] ] Here is ...
24 views

### Software usage TestU01

I'm doing some statistical test on a RNG and I'm trying to use this. I've asked somethings on the crypto subsite about the dieharder tests suits and they closed my question because "programming" was ...
57 views

### Galois pseudo random number generator doen't work for 16-bit maximal-period in code composer studio

I am using MSP430FR5969 microcontroller with code composer studio IDE to make a pseudo-random number generator. I referred to this wikipedia page for that. It works fine with 8-bit but in case of 16-...
30 views

### Can PHP's random_int be relied for unique integer genrator (reasonably)

I have an application, which will require around 200K batch IDs to be generated every year. I first thought of using uniqid() to generate batch IDs, but this will return be string, which will take up ...
18 views

### JavaScript - Sound does not play along with random values

I have a function that displays a random word from an array of objects, in a non-repeated way. My goal is to make it play a sound clip with each word (that sound would be the word's pronounciation). ...
35 views

### How to select random record from mysql database

I need to select say 2000000 records at random from a very large database. I looked at previous questions. So please do not mark this question as duplicate. I need clarification. Most answers suggest ...
24 views

### JavaScript - Play audio along with randomly generated values

I have a function that displays a random word from an array, in a non-repeated way. I would also like to play a sound clip with each word (that sound would be the word's pronounciation). I know how ...
27 views

### Javascript - Compare user input value to randomly generated value

I have a function that displays a random word from an array, in a non-repeated way, and a textbox where the user is supposed to type the same generated word. I tried using a switch statement to ...
29 views

### shuffling all elements between given two elements [duplicate]

I know how to shuffle a list of elements. But hos should I do if I want to shuffle all the elements between two specific elements. import random x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] random.shuffle(x) ...
42 views

### How can I check if a number is equal to a random number between 1 and the value of the number?

I have a variable phrase.points that can have a value of between 1 and x. What I would like to do is something like this: if (phrase.points == random number generated between 1 and x) return; ...
108 views

### How to randomize a number based on criteria in C#?

I am struggling with a randomize algorithm which I'm unable to solve. Below is the randomize criteria. User type a random integer number, i.e 28 User type a factor number, i.e 1.2 If user key in 28 ...
42 views

### two dimensional array with random numbers doesn't change

I'm creating an 2-dim Array with random numbers from [0,9] and it works, but after i execute it the second time the matrix doesn't change. Why ? Everytime i execute my code i want a new random matrix,...
23 views

### random return not matching outcome requirements

python3.7 I am trying to use a simple "dice" code to (originally) allow for a 50/50 chance between two outcomes. However I have noticed that this code does not consistently match the outcome I ...
23 views

### Chrome Selenium IDE random number generator

I saw similar topics but nothing exact. When I used Firefox and the IDE I was able to use StoreEval | Math.round (Math.random() * 99999999999) to create a random number of a specific length. I have ...
69 views

### Printing random array element in C89 [on hold]

I have the following code that works fine: #include <stdio.h> #include <stdlib.h>/*need this for rand()*/ #include "random.h" #include <time.h>/*for time() function*/ int main() { ...
55 views

### One time pad encryptions in java

I've create a one time pad encryption in java but I have two problems which are : In Encryption, how can I can make the size of the key flexible according to the size of the plaintext and generated ...
66 views

### How do I return a number of random numbers from this string?

I have converted my string, just_numbers, to an array format with: System.out.println("just_numbers" + Arrays.toString(just_numbers)); It looks like [28, 27, 49, 25, 2, 23, 48, 18, 57, 58, 60, 20] ...
37 views

### count zero occurences by choosing randomly

Say I have following list with some values, which I retrieved from a json file: def read_json(object): categories_list = [] object=json.loads(object) for feature in object['features']: ...
45 views

### Making an array with sets of numbers in Java

I am making a memory game. Currently I am stuck at the initialisation part of the board. I want to make an array filled with 36 numbers and it should have 18 sets of numbers (so 1 and 1, 2 and 2 etc.)....
38 views

### Fetch random town names based on countries

I've been struggling with this for a while now, and I've gotten somewhere between having it work once in a blue moon and completely breaking down. My ultimate goal is to replace the "!R"s in the ...
63 views

### Python random.choice same output

I'm trying to random some strings in a variable, myTest = random.choice(["test1","test2","test3"]) print(myTest) print(myTets) print(myTest) And when I'm running my script all of them are the same ...
22 views

### Giving priority in MySQL query? [duplicate]

Here is my database: Table: Jackpot Username | Credits Jake | 5 Zack | 5 I want to select randomly from this table where people with more credits would have a higher chance of being ...
19 views

### Pygame - Issue with Randomly Generating Sprites

I need help with randomly generating sprites. The idea is: One head moves down the screen. Once it leaves the screen, a new random head starts moving down the screen. And so on... I have 4 images I ...
49 views

### How to fix small but relevant Python errors?

I'm currently attempting to make a coding program, imitating the "Library of Babel" website. Basically what it does now, is it generates a pseudo random string of letters based on a kew, and allows ...
78 views

### Generating the same random numbers with threads in OMP

I am attempting to multithread some code with OMP. Currently my sequentially version using rand() to generate a set of random numbers with a consistent seed so that they return the same results when ...
58 views

### randomly rename files in php

I have a folder of 1000 images and I need to randomly rename them from 1.jpg to 1000.jpg , it must be completely random each time I run the script. I just need that 1.jpg is different each time I run ...
54 views

### Creating fake data in Python

I am trying to create a function that creates fake data to use in a separate analysis. Here are the requirements for the function. Problem 1 In this problem you will create fake data using numpy. ...
70 views

### Javascript random number generator (generates every number once) using input

I am making a random ticket generator which asks range and when pressing button generates a random number in the range of that number. The code is missing an important part: generated numbers can't ...
42 views

### c# Random gives the same number [duplicate]

My program generates a random integer between 0 and 1000 using System.Random at second once. The problem is, because it generates in the same millisecond time, the value always the same. How can I get ...
19 views

### Random number with VBA

I am trying to create random numbers in within normal distribution given random probabilities in a range. My code is the following: Range(Cells(2, 1), Cells(RandomNumbers + 1, 1)) = WorksheetFunction....
42 views

### Why does my srand(time(NULL)) function generate the same number every time in c? [duplicate]

So I was creating a program that would call a function and return 0 or 1 (0 meaning tails and 1 meaning heads) and then use that to print the outcome of 100 flips. It seemed simple enough thinking I ...
188 views

### Why is the use of rand() considered bad?

I heard some guys telling that the use of rand() is bad EVEN AFTER USING srand() to get a seed. Why is that so? I want to know how the stuff happens... And sorry for another question.. but what is an ...
51 views

### How to Print Random number in a Math Table?

I am implementing a math table using two integers (a and tableSize). I have built a random operation named R. I am going to calculate a random number between the row and column range and print the ...