Questions tagged [random]

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

random
Filter by
Sorted by
Tagged with
3 votes
3 answers
1k views

Creating a list of random elements using recursion

I was asked to define a recursive function that takes in two parameters: n valmax and returns a list of n numbers picked randomly from the interval [0 , valmax] ` import random def random_list(n, ...
0 votes
4 answers
218 views

Random Array of username prefixes

Modifying my chat website and I want to add a random assortment of prefixes when people join. right not the php code is: define("ANONYMOUS_PREFIX", "user"); which outputs as: user9367 joined. Here's ...
1 vote
2 answers
34 views

NumPy writing windings instead of numbers to CSV in ArcMap

I'm using this code: import arcpy import numpy as np f = open("F:\INTRO_PY\LAB_7\lab_7.csv","w") array = np.random.rand(1000,1000) f.write(array) f.close in order to create a 1000x1000 random ...
0 votes
1 answer
994 views

adding random shapes Rectangles, Ellipses and lines in JAVA GUI

Hey there i'm trying to design a GUI program ShapeFactory that has Buttons to produce : a. Random Rectangles with random colors. b. Random Ellipses with random colors. c. Random Lines with random ...
1 vote
1 answer
1k views

Set a minimum value for randomly generated numbers [duplicate]

I am using this function to generate and alternate random values inside a div var change_price = $('#myprice'); animationTimer = setInterval(function() { change_price.text( ''+ Math.floor(...
4 votes
1 answer
111 views

Why is glibc's __random_r assigning variables it immediately overwrites?

I was looking for the source for glibc's rand() function, which an answer here links to. Following the link, I'm puzzled about the code for the __random_r() TYPE_0 branch: int32_t val = state[0]; ...
1 vote
1 answer
535 views

Pandas merge handling duplicates in join output

Is there a nice way to bring only one row, preferably random in one-to-many matching during left join in Pandas? e.g left = [[1,1,1], [2,2,2],[3,3,3], [9,9,9], [1,3,2]] right = [[1,2,2],[1,2,3],[3,...
1 vote
1 answer
377 views

Generate random variable with known PDF expression in MATLAB

I know the probability density function (PDF) expression of random variable r as 2r/R^2 where 0<=r<=R. Then, its CDF is r^2/R^2. Can someone help me to generate random variable r in MATLAB ...
0 votes
2 answers
52 views

I get very strange error while im trying to finish my project

This code is meant to pick an artist from internal file (text file), read it and pick randomly from the internal file the artist (that are in the text file in array style, e.g., "carrot apple banana"),...
1 vote
2 answers
1k views

Concurrent tasks deterministically generating pseudo random numbers

I have a coroutine that returns a list of pseudo-random bytes import asyncio import random import os async def random_bytes(): random.seed(a=1234) results = [] for _ in range(0, 128): ...
0 votes
2 answers
2k views

Javascript random quiz but more than 1 asked

I have made this code which displays a random question each time a page is refreshed or clicked. However, i want it to display not just one random question but 3 different ones which are randomized ...
0 votes
1 answer
35 views

How to make a non list Loop that will select 4 random numbers from 1-10, and display them, but they cannot be the same?

import random counter = 0 count = 0 counting = 0 valueOne = 0 valueTwo = 0 while counter ==0: playerOne = random.randint(1,10) number = random.randint(1,10) About right here is where I get ...
0 votes
1 answer
1k views

Python- If condition for a variable True, execute function assigning new variable until False

I've not ever encountered this type of situation in a Python for loop before. I have a dictionary of Names (key) and Regions (value). I want to match up each Name with two other names. The matched ...
1 vote
1 answer
342 views

random byte to int java

In the Random class, define a nextByte method that returns a value of the primitive type byte. The values returned in a sequence of calls should be uniformly distributed over all the possible values ...
0 votes
1 answer
52 views

How do I correctly randomize this specific data?

I would like to randomize Tests and the order of their versions. My data should look like this in the end: > # subject Test t1 t2 t3 t4 > # 1 1 PFT A B C D > # 2 ...
1 vote
2 answers
112 views

How can I use NIST software in non-interactive way?

I am using NIST software. This tool (written in C) has interactive mode. It gets an input file, asks user some questions about test type and parameters, and then runs the test. I want to run it on ...
5 votes
3 answers
11k views

List with random numbers in Haskell

I want to generate a list with random numbers in Haskell. I have to use the import System.Random library. I started doing something like that but it doesn't work. I have to create a list with N ...
1 vote
2 answers
805 views

Html Canvas random start position to move afterwards

I am currently learning JavaScript. I want the random start position of the cube to go up and down. This will cause the cubes to jump up and down on the Y axis. I want the cubes to move up and down ...
1 vote
3 answers
2k views

C# inserting numbers into a list box in sorted position

Excuse my nooby first post please. I am having an issue with a univerity assignment. The assignment is a "Number list manager", basically user chooses a radio button (sorted or unsorted) and when they ...
3 votes
1 answer
159 views

Producing random variates distributed hypergeometrically

How can we generate random variates for a hypergeometric distribution in C++? Unfortunately, the standard library does not supply a std::hypergeometric_distribution. There is a boost::math::...
1 vote
1 answer
28 views

Randomzing the order of two scales using shuffle and foreach() in PHP

I am a bit lost with my code and been trying to solve my problem for quite a while now. I think it cannot be that hard but still I cnnot wrap my had around it. I have two questionnaires which I want ...
1 vote
1 answer
597 views

random.Next() not returning random only returning 0 - C#

I'm sure this will get marked as a duplicate, but I genuinely have tried to figure this out. Here goes nothing. I have come across a problem while working through an exercise in Head First C#. My ...
0 votes
1 answer
116 views

C++ Class Object Counter As Random with Static Member

First of all I do my researches but because I couldn't learn it in lesson well, other answers weren't usable for me. Now my teacher asks from this code that my counter must be initialized by a static ...
0 votes
1 answer
2k views

Javascript implementation of Java's Random class that will generate same sequences with same seed

1st I did multiple searches here and via google trying to find this so sorry ahead of time if I didn't use the right search terms to find it. I'm rewriting some legacy Java code into Javascript and I'...
1 vote
1 answer
240 views

std::normal_distribution result for the same generator value?

I noticed a very weird behavior with GNU C++ standard library. When using a custom generator with normal distribution, it seems the distribution might return different values even for the same ...
0 votes
1 answer
2k views

Generate a Connected Graph java

I want to write a function, which is given a set of vertices and then develops an edge between 2 vertices and repeats this until the graph becomes a connected graph). How can I tell when the graph has ...
0 votes
2 answers
36 views

Random switch bound depending on filled TextViews

I started coding some months ago and started practicing on my own app. Six names can be entered and after that random names are matches with random tasks, which works fine if you enter all six names. ...
1 vote
5 answers
966 views

java random number generator without arrays

I am completely new to Java and working on an assignment. I need to generate 6 random numbers within the range of 1 - 49, which is simple. However, the complication is that the numbers cannot ...
3 votes
1 answer
817 views

Random without duplicate using stream and questions about sort Java

I am trying to get 8 random int using stream but the problem with the code below is that distinct() removes duplicate which will not give me 8 int if there was any duplicate. Goal: 1.Get 8 random ...
0 votes
4 answers
619 views

Call a list of functions with random parameters

How can I call a set of functions using random arguments. import random def sum_3 (a): return (sum(a) + 3) def sum_2 (b): return (sum(b) + 2) # Call the functions functions = [sum_3, sum_2]...
3 votes
3 answers
668 views

How to randomly choose method from a list of methods with different arguments?

I have object a of class b with methods foo(), boo(), noo(arg). Now I want to randomly choose one of them without extending the class b. The problem is that if I use technics supposed here: Syntax to ...
1 vote
1 answer
44 views

How can I look at a specific generated train and test sets made from for loop?

My program divides my dataset into train and test set, builds a decision tree based on the train and test set and calculates the accuracy, sensitivity and the specifity of the confusion matrix. I ...
1 vote
1 answer
1k views

What is the scala equivalent of Python's Numpy np.random.choice?(Random weighted selection in scala)

I was looking for Scala's equivalent code or underlying theory for pythons np.random.choice (Numpy as np). I have a similar implementation that uses Python's np.random.choice method to select the ...
1 vote
1 answer
60 views

R - create random numbers

I have huge dataframe like this: df <- read.table(text=" id date 1 1 2016-12-01 2 2 2016-12-02 3 4 2017-01-03 4 ...
1 vote
2 answers
54 views

How to add random values into an empty vector repeatedly without knowing when it would stop? How to count average number of steps?

Imagine the process of forming a vector v by starting with the empty vector and then repeatedly putting a randomly chosen number from 1 to 20 on the end of v. How could you use Matlab to investigate ...
2 votes
1 answer
1k views

Multiple Turtles, multiple random movements

I have an assignment where I have to make a game in python with turtles. I am able to generate a grid like I want to, and I am able to generate multiple different turtles. my - I have no clue where ...
0 votes
1 answer
753 views

c# Lottery looping program with Visual Studio

I am currently trying to figure out how to create a program within Visual Studio, that matches 3 numbers, 1-9, given in a textbox with 3 random generated numbers in a listbox. I am having trouble ...
0 votes
2 answers
428 views

random sample n digits from range of (x,y) that average to mean k?

I am trying to random sample n=15 digits from range(low=3, high=7) that when summing the sampled 15 digits, they average to 5. So far I've managed only to random sample n digits from certain range ...
0 votes
4 answers
69 views

Javascript Array - getting random photo to display when browser loads

Free Code Camp Project I am working on a tribute page project, and have decided to add a javascript random photo array to the project. This is working fine, but I cant figure out how to get a random ...
-1 votes
1 answer
58 views

Getting half a string array at random no matter array size

I am trying to create a function that takes half of the names at random and spits them back out. This is what I have currently: ` var shuffle = require('shuffle-array') return ( <h1>{...
0 votes
1 answer
52 views

Range of a java statement

just a quick question. I'm pretty new to programming and I'm having trouble figuring out what the range of e = rand.nextInt(10) * 4 would be. Can someone please help me out? I've already tried all ...
0 votes
2 answers
267 views

sampe vector of points from truncated exponential distribution with specific average

I create a truncated exponential distribution: from scipy.stats import truncexpon truncexp = truncexpon(b = 8) Now I want to sample 8 points from this distribution, such that their mean with be ...
0 votes
1 answer
34 views

jquery random background - different eveytime

I have a random background set to a div. I was wondering if it was possible for when the background changes it will display a different background every time and not duplicate from within my image ...
1 vote
3 answers
8k views

Unique random integers in postgresql

Is there a way to generate unique (distinct) random numbers in posgresql (and redshift in particular)? The following code generates 5 random integers from 1 to 10 with replacement: SELECT round(...
-1 votes
1 answer
59 views

How to display a random background image while avoiding repetition of those images?

I have this JS code which includes an array of (currently) 4 images and a function that chooses a random image: const scenes = ['url(scenes/scene1.jpg)', 'url(scenes/scene2.jpg)', 'url(scenes/...
0 votes
1 answer
43 views

Getting the first index of a array does not move

I Insert code and explain the problem: public static void nextPermutationArray(int[] v) { int x = 0; int y = 0; Random r = new Random(); while (x < v.length) { y = x + r....
0 votes
2 answers
259 views

load 1 random image (maybe 10 images) in 1 div tag

I am not a true programmer and need some help. I need a script that inserts a div tag and within that div tag have a random image load (from a list of 10) when the page laods from an external js file....
3 votes
3 answers
3k views

Unique random string with alphanumberic required in Ruby

I'm using the following code to generate a unique 10-character random string of [A-Z a-z 0-9] in Ruby: random_code = [*('a'..'z'),*('0'..'9'),*('A'..'Z')].shuffle[0, 10].join However, sometimes this ...
0 votes
1 answer
125 views

What is the maximum number of pseudo-random numbers that can be generated with numpy.random before the sequence begins to repeat?

I need to generate many hundreds of millions of random numbers for a clustering analysis. I am using numpy.random and was wondering if anyone knows the maximum number of pseudo-randoms that can be ...
0 votes
1 answer
59 views

how to fix the randomized data for entire program in r [closed]

I am working with iris data and I want to randomize/shuffle the data. The extract random 80% of the data to train. However each time I run my code I get a new order. library(caret) iris_data <- ...

1
262 263
264
265 266
714