# Questions tagged [random]

12729 questions

0

votes

1

answer

45

Views

### Random generator creates the same numbers

While looping through a for loop which is randomly 1-10 long. I also go through a while loop. I am trying to find 6 random numbers between 1-42. I then do that again (1-10) times. Currently, these 6 random numbers stay the same. I suspect it has something to do with the seed but I could not solve it...

1

votes

1

answer

266

Views

### relation between random testing and fuzz testing

I am wondering what the relation between random and fuzz testing is. I understand that random testing has been there for a longer time, but I cannot see any differences between them. They both seem to make use of random input to see if the program goes into an unexpected state (i.e. crash). Is the m...

0

votes

2

answer

23

Views

### (Java) I can't figure out how to populate an array with a counter controlled loop which is required

I have to:
Create an array that models a deck of cards. For example, “1_of_diamonds” represents the ace of
diamonds, “2_of_diamonds” represents the 2 of diamonds, up to “13_of_diamonds”, which
represents the King of diamonds. The suits clubs, hearts and spades are represented in a simila...

1

votes

1

answer

36

Views

### In Twilio, can you <Play> a random audio file from a list of provided URLs for incoming calls?

Using Twilio for an interactive art exhibition where you call the number and listen to the audio in the gallery. I'd like for incoming callers to not always hear the same 20-30 seconds of audio at the beginning of the audio file. Is it possible to provide 3-4 different audio files and one of them is...

1

votes

1

answer

28

Views

### Ints or doubles when modelling random events

Theoretically, if I want to model an event in which the probability is 50%, I could merely generate a Boolean and do the event if it returned true, for example.
Now, this could also be achieved by generating a random double, between 0 and 100 (inclusive) and do the event if the number is greater tha...

1

votes

1

answer

25

Views

### Simulation of multiple binomial random numbers in R

I have the following algorithm
Step 1. Generate X1=x1~Bin(6,1/3)
Step 2. Generate X2|X1=x1~Bin(6-x1,(1/3)/(1-1/3))
Step 3. Generate X3|X1=x1,X2=x2~Bin(6-x1-x2,(1/3)/(1-1/3-1/3))
Step 4. Repeat step 1-3 N times.
Here is my approach to implement this algorithm in R:
mult_binom

1

votes

2

answer

25

Views

### Generate random numbers in each row between 1 and a particular value in a column

I am stuck for quite a while now and really interested in how to achieve this. I have a data frame and I want to add another column with random numbers between 1 and the number that is in that row under the column Amount. How can I do this?
This is what I have now:
dataframe$newColumn

0

votes

0

answer

3

Views

### Getting a random number in a function in OCAML OR Telling compiler to evaluate function each time

I'm new to OCAML and was playing around with putting a marker on a random 5X5 square. I've written the example program below. 'silly_method1' works but notice that it takes an argument. I don't really have argument to pass in for what I want. I'm just asking for a random number to create my robo...

0

votes

0

answer

5

Views

### How to have a unique random number generated in a csv file every time without manual intervention?

I need to pass 10 digit alpha numeric random value (e.g. AUT******* where * denotes any random number) in a csv file.
Contents of csv file:
Code,Account1,Account2,Account3
AUT*******,ABC,DEF,GHI
This csv file will be uploaded in to a web application every time to perform some operation.
I need this...

-2

votes

1

answer

24

Views

### How can I make an if-statement based on what has randomly been printed?

so I am creating a type of game that will involve dices. What I plan on doing is to have different things happening depending on what the player throws, it will be a 2 player game.
What I want to do is make the computer randomly generate 2 of the 6 possible dice sides. After that has been printed,...

1

votes

2

answer

537

Views

### Why doesn't Python 3.4 randrange want to work? [closed]

I am currently working on making a small Pokemon game for me and my friends. But to do this, I was going to use the randrange module to randomize which questions were used instead of being in order. I did this, but everytime I run the program, it doesn't do what it needs to do, it just sits at a bla...

1

votes

2

answer

295

Views

### does random number in the real world follow uniform distribution

I am confused about the concept of uniform distribution and random number. Does random number follow uniform distribution or does random number not follow any distribution?

1

votes

4

answer

1.1k

Views

### putting random alphabetical letters in 2 dimensional array in java

I am suppose to create a 2 dimensional array that contains alphabetical letters that are all capitalized. The goal of the program is basically building a word search puzzle, and I want to fill the 2 dimensional arrays with random alphabetical letters but with the code that I have currently, the tabl...

0

votes

4

answer

23

Views

### How to fill array with random numbers limited to 0-20

I am having trouble placing the random generator in the array, how can I get #20 random numbers from 0-9 in the array? Then you count the occurrences of those numbers.
import java.util.Random;
public class CountDigits {
public static void main(String[] args) {
Random digit = new Random();
int Rando...

1

votes

1

answer

40

Views

### Random sets with three random numbers in it (sampling random points in a cube)

Each point inside a cube has three values (X, Y & Z axes). There are in-built functions in R, pertaining to the generation of sets with single random number (one number per observation), such as runif(), sample(), rnorm(), set.seed() etc. Thinking in a similar logic, the numbers are generated in a...

1

votes

3

answer

65

Views

### How to sort a vector according to a given sequence in R

I'm trying to organize a sequence of data according to a given sequence. For example, the given sequence I have is
set.seed(1)
given_seq

1

votes

3

answer

36

Views

### How to use the constant outcome of a random formed function in python

let's look at the example blow
import numpy as np
def Test2(t):
ran=np.random.randint(5)
return t-ran
def Test3(t):
test2=Test2(t)
return t**2-test2
a1=Test3(1.0)
a2=Test3(1.0)
a3=Test3(1.0)
print(a1==a2,a1==a3,a2==a3)
the answer is fal...

1

votes

2

answer

18

Views

### How do I select a random word within a cell?

I want randomly to select a word from a cell that is generated by a form field using the 'paragraph' answer option.

1

votes

1

answer

38

Views

### Select random and unique elements from a vector

Say I have a simple vector with repeated elements:
a

1

votes

1

answer

79

Views

### Where can I find the source code of os.urandom()?

I want to investigate and study the code of python 3.7's os.urandom() function.
I had a look at the respective standard library's os.py, but neither is it defined there, nor is it imported there.
I also tried to grep for the definition:
/usr/lib/python3.7 $ grep -rFl 'def urandom' 2> /dev/null
But n...

1

votes

2

answer

103

Views

### Idiomatic way to get a random number that is different from a previous one?

Is there a better way to do this in Rust?
let mut current_index = rng.gen_range(0, 5);
while current_index == previous_index {
current_index = rng.gen_range(0, 5);
}

1

votes

2

answer

56

Views

### Is there a random number generator which can skip/drop N draws in O(1)?

Is there any (non-cryptographic) pseudo random number generator that can skip/drop N draws in O(1), or maybe O(log N) but smaller than O(N).
Especially for parallel applications it would be of advantage to have a generator of the above type. Image you want to generate an array of random numbers. One...

1

votes

3

answer

68

Views

### How to generate random data off of existing sample data?

I have a set of existing data, lets say:
sample_data = [2,2,2,2,2,2,3,3,3,3,4,4,4,4,4]
off of this sample data, i would like to generate a random set of data of a certain length. This should not be off of the sample data, but off of a distribution that was generated off of the sample data.
expected...

1

votes

1

answer

74

Views

### why does rand() give relatively close numbers? [duplicate]

This question already has an answer here:
srand(time(NULL)) generating similar results [duplicate]
8 answers
I am using the rand() function in c++ yet i am getting very close numbers every time here is my code`
int pickrandom(){
time_t t;
time(&t);
srand (t);
return rand();
}
I get numbers like : 1...

1

votes

1

answer

76

Views

### How does IntRange.random() introduce entropy in Kotlin

I'm planning on using IntRange.random() (i.e. (0..9999).random()) to generate a random 5 digit code in Kotlin. It's important that malicious people cannot predict the sequence of numbers that will be generated.
Does IntRange.random() ensures that there is entropy when generating these numbers? i.e....

1

votes

1

answer

46

Views

### Matlab: random integers from a range with no repetition

I want to get an array with randomized integer included in range with no repeat, I used :
randperm(15,3)
output is :
8, 10, 12
This function not use a range, I would like to random values only from 10 e.g.
Thank you !

1

votes

2

answer

68

Views

### How to find a random item from a C# list that has a specific value?

I'm trying to find an item from a list that has a field with a specific value; some entries will have the same value for this field, and in that case, I would like to return one of those at random. Does the List.Find function return one randomly if there are multiple entries that satisfy the criteri...

1

votes

2

answer

62

Views

### Random numberGenerator

For my assignment, I need to write the following attribute:
Write a class Deck. A Deck has the following private attribute:
A static Random numberGenerator.
Initialize the Random numberGenerator 'in place' (i.e. on the same line as its declaration) with a reference to a Random object created with th...

1

votes

1

answer

61

Views

### Generating a random bit stream in Rcpp efficiently

I have an auxiliary function in the R package I'm currently building named rbinom01. Note that it calls random(3).
int rbinom01(int size) {
if (!size) {
return 0;
}
int64_t result = 0;
while (size >= 32) {
result += __builtin_popcount(random());
size -= 32;
}
result += __builtin_popcount(random() &...

-2

votes

2

answer

23

Views

### random.randint() call with -1?

Can someone explain why the range in the random.randint(0, len(messages) - 1) has a minus 1 at the end? The list has 9 values:
import random
messages = ['It is certain',
'It is decidedly so',
'Yes definitely',
'Reply hazy try again',
'Ask again later',
'Concentrate and ask again',
'My reply is no',...

1

votes

0

answer

81

Views

### c++ async : how to shuffle a vector in multithread context?

Running a multithreaded program, I noticed that the program was running faster using 1 thread compared to 4 threads, despite the CPU having 4 cores.
After investigating, I found out that the issue appears only when shuffling something.
Below the minimal program I created to reproduce the problem:
#i...

0

votes

1

answer

18

Views

### Random Image Generator not finding image in directory

I'm working on a very simple webpage that contains just a button that generates a random image above it.
I've searched online but none of the answers seem to solve my problem.
I have a js code that seems to be working: it generates a random number but when I try to link the number to '.jpg' (That's...

1

votes

1

answer

608

Views

### How to interpret the output of H2O .predict method for random forest classification?

When I use the predict method on my trained model I get an output that is 1 row and 206 columns. it seems to have 206 values ranging in values from 0-1. This sort of makes sense as the model's output is categorical variable with values 0 and 1 as possible values. But I don't get the 206 values, as I...

1

votes

1

answer

713

Views

### Multiclass classification of text in R

I have build a random forest for multiclass text classification. The model returned an accuracy of 75 %. There are 6 labels, however out of the 6 classes, only 3 are classified and rest are not classified. I would really appreciate if anyone could let me know what went wrong.
Below are the steps i f...

1

votes

1

answer

1.2k

Views

### How to set sampsize for random-forest on unbalanced data

I want to build a species distribution model using random-forest:
My training data consists of 971 records of species presence (71)/absence (900) and three environmental variables at systematically sampled points (4*4m, random starting point).
Training data:
str(train)
'data.frame': 971 obs. of...

1

votes

1

answer

58

Views

### How does python pre-process the script and read files efficiently for fixed subset of large amount of images

I need to read a subset of files from a large number of files. To read the subset of the files, we will first provide a list of indices to obtain the filenames, and use some python classes to read the subset of files using the filenames.
Let's say we have 15,000 images with the filenames stored in t...

1

votes

1

answer

299

Views

### Create a random bijective function which has same domain and range

Create a random bijective function which has same domain and range.
By random bijective function I mean a function which maps the elements from domain to range using a random algorithm (or at least a pseudo-random algo), and not something like x=y. The domain and range can be a very small set someti...

1

votes

1

answer

211

Views

### 1D Random Walk Expected Value

I have implemented a 1D random walk in C++ and Python; however, in both programs the expected value is not sqrt(N). I am wondering if there is a logic error in my code or some hidden factor that is making my outcome consistently low.
For those unfamiliar with random walk, the expected RMS value is s...

1

votes

1

answer

1.8k

Views

### tensorflow random forest regression

I would like to implement a simple random forest regression to predict a value. The inputs are some samples with several features, and the label is a value. However, I cannot find a simple example about the random forest regression problem. Thus, I saw the document of tensorflow and I found that:
An...

1

votes

0

answer

552

Views

### Text Categorization by uisng mlr package in R

I need to train a model which would perform multilabel multiclass categorization on text data.
Currently, i'm using mlr package in R. But unluckily I didn't proceed further because of the error I got it before training a model.
More specifically I'm stuck in this place:
classify.task = makeMultilabe...