# Questions tagged [random]

10059 questions

0

votes

0

answer

4

Views

### how to crack RandomUtils.nextInt(a,b) by knowing some num seq

for example,
These three values (79,81,98) come from org.apache.commons.lang3.RandomUtils.nextInt(2,101) ,
how can I get the seed and predict the following numbers ?

0

votes

1

answer

26

Views

### PHP random number no repeat

Seems to be duplicate title, but i accesed all links and none of the pages helped me.
I have the following code:
//Check if form was submitted
if($_POST){
$number = $_POST['number'];
$selected_choice = $_POST['choice'];
$next=$number+1;
$total=4;
//Get total number of questions
$query="SELECT...

0

votes

1

answer

20

Views

### Counting elements in a list with a given number of elements

I want to create two lists. The first has x elements, 'Name n', where (1

0

votes

0

answer

5

Views

### Generate A Blank Image From Width And Height In VB.NET

I want to make a blank canvas bitmap image with a certain width and height, in VB.NET, I am using Visual Studio 2017, with a Windows Forms Application, and .NET Framework 4.6.1.
I tried creating a new bitmap image based of a new image with parameters of the width and height, but that didn't really w...

1

votes

1

answer

72

Views

### Random Forest Black Box with CleverHans

I am new to this stuff and trying to attack Random Forest with Black Box FGSM (from clever hans)
But I'm not sure how to implement it. They've a blackbox example for Mnist data but I dont understand where should I put my random forest and where should I attack. Any help would be appreciated.

1

votes

1

answer

55

Views

### How to generate uniform random points inside d-dimension ball / sphere?

I've looked around and all solutions for generating uniform random points in/on the unit ball are designed for 2 or 3 dimensions.
What is a (tractable) way to generate uniform random points inside a ball in arbitrary dimension? Particularly, not just on the surface of the ball.
To preface, generatin...

1

votes

2

answer

32

Views

### Generating an NxM array of uniformly distributed random numbers over a stated interval (not [0,1)) in numpy

I am aware of the numpy.random.rand() command, however there doesn't seem to be any variables allowing you to adjust the uniform interval in which the numbers are chosen to something other than [0,1).
I considered using a for loop i.e. initiating a zero array of the needed size, and using numpy.rand...

1

votes

1

answer

28

Views

### Getting a random function from a list of functions and calling the selected function

I'm trying to create a function that I can call and it selects a random function from a list of functions and calls the selected function into action. Is that even possible? Here what I have tried. Which results in nothing happening.
import random
def ran1():
print("test1")
def ran2():
print("tes...

1

votes

1

answer

45

Views

### When defining keys in table, why is it inserted in a random order?

While working on a Love2d project, I noticed that when defining tables with a key and putting said tables in another table, in a loop, the tables were being inserted in a random order.
To test this, I made a short script that will hopefully explain my predicament a little better. My first assumption...

1

votes

1

answer

488

Views

### Using RAND() in Zend Framework

My client website using Zendframework. Now they ask me to random the result. I using RAND() but not working. Anybody can help?
Here is the code (the RAND() at the bottom)
$oPlaceSelect = $oPlaces->select()->setIntegrityCheck(false)
->from(array('p' => 'places'),
array('id', 'place_title' => 'title',...

-3

votes

2

answer

25

Views

### Random Number Generation in C# errors out

So i am trying to generate a random number and if the number is 3 or 8 i what something to happen , it this case to add 1 to one of the 2 integers
keep in mind i really am only going off a book in C# and some knowledge in VB
int Number1 = 0;
int Number12 = 0;
string text;
string text2;
Exexs:
Rando...

-3

votes

0

answer

17

Views

### guess a number between 1 and 100

I am thinking of a number from 1 to 100. You and your sibling have gotten into a fight over who gets the last brownie. Write a program that comes up with a secret number between 1 and 100 and prompts each user for an integer. Whatever number is closest to the secret number wins. Be sure that your pr...

0

votes

0

answer

8

Views

### What is the difference between predict() function and the model$predicted in case of a random forest model in R?

Using random forest package:-
#install.packages("randomForest")
library(randomForest)
I used an online code to run random forest on my system. I got a model with confusion matrix and accuracy etc.
Now, my data is in the form of training and validation sets. I got the data from here:-
https://archive...

1

votes

1

answer

1k

Views

### Alternative to std::default_random_engine for Xcode?

I'm trying to compile a program I wrote in linux on Xcode and for my random functions I used:
std::random_device seed_device;
std::default_random_engine engine(seed_device());
But default_random_engine won't compile on Xcode. Is there a different version I should use?

1

votes

3

answer

574

Views

### Generate Random Mathematical Functions

This is kind of a weird question, and might not be entirely appropriate for Stack Overflow, but I couldn't find anything about it online, so here it is...
Is there a way (or what is the best way) to generate random mathematical functions? By this I don't mean that I want a function that generates a...

1

votes

1

answer

28

Views

### Retrieve an object from an array with a specific parameter

I was wondering whether there is an easy way to select a random object from an array where one of the objects attributes matches a variable.
Something like this:
var ninjas = [
{ name: "Sanji Wu", affiliation: "good" },
{ name: "Chian Xi", affiliation: "good" },
{ name: "Chansi Xian", affiliatio...

1

votes

3

answer

3.3k

Views

### how to use order by random in codeigniter

While Searching I want to show the paid customers firstly, and then rest of customers list
but the problem is I want to show by random
for Example. paid customers should not mix with others.
Can anyone tell what will be query?
please help me!
I am using codeigniter

2

votes

2

answer

142

Views

### If statement using IO Int haskell

I have a game , user vs computer and I want to randomly choose who starts the game. I have
a = getStdRandom $ randomR (0, 1)
This gets a random number 0 or 1. However it is a IO Int, so I can't have an if statement comparing it to a number like
if a == 0 then userStarts else computerStarts
I have...

0

votes

2

answer

16

Views

### How to create a new list that is combination of 2 different lists elements without repetition?

I am trying to create a canvas that has 2 stimulis. Please note that stimuli lists can be longer.
sti1 = ["death", "pain"]
sti2 = ["glass", "book"]
These stimulis will shown like this:
frame 1: death - book / frame 2: glass - pain
But they must shuffle correctly. I mean if there is a "death x book...

1

votes

4

answer

168

Views

### Create number for random and non repeat

i'm code:
Random rand = new Random();
int[] arr = new int[4];
for (int i = 0; i < 4; i++)
{
for (int k = 0; k < 4; k++)
{
int rad = rand.Next(1, 5);
if (arr[k] != rad)
arr[i] = rad;
}
}
for (int i = 0; i < 4; i++)
MessageBox.Show(arr[i].ToString());
I wanna production numbers from 1 to 4 am and uneq...

7

votes

1

answer

40

Views

### How can I restart a CSS animation with random values in a loop?

I have an element which is randomly animated with CSS and JS with the help of CSS custom properties in the following way:
HTML:
CSS:
#my-element {
width: 50px;
height: 50px;
background: #333;
}
:root {
--animation-name: vibrate-1;
}
#my-element {
animation: 3.3s 1 alternate var(--animation-name);
}...

1

votes

1

answer

274

Views

### What is membership in community detection? [closed]

I am finding it hard to understand what membership and modularity returns and why is it exactly used.
wc

1

votes

2

answer

668

Views

### Subsample size in scikit-learn RandomForestClassifier

How is it possible to control the size of the subsample used for the training of each tree in the forest?
According to the documentation of scikit-learn:
A random forest is a meta estimator that fits a number of decision
tree classifiers on various sub-samples of the dataset and use
averaging to imp...

0

votes

3

answer

24

Views

### jQuery: Sometimes random fails

I have a blog which advertises x3 articles randomly at the bottom of each post. Sometimes, this feature fails to display all 3 (1 missing).
I can't see where the problem lies.
JQuery
$.get("https://www.citychurchchristchurch.co.nz/blog.php", function(data) {
var $quotes = $(data).find(".container-a...

1

votes

2

answer

196

Views

### Picasso download random image

in my new app, at some point I need to fetch a random image (i use this link) using Picasso. The problem is even if I set the network policy to no cache the image stays the same if I exit the activity and relaunch it.
Note it's the second activity that contains this Picasso downloading

1

votes

2

answer

927

Views

### How do i generate a random maze in java?

Ok, so i want t generate a random maze for my maze game.
I have hardcoded the maze like this, and have several different versions that i would like to be able to have spawned at random.
public Maze() {
this.mazeMap1 = new BlockType[][] {
{H, H, H, H, H, H, H, H, H, H, H, H, H, H, H},
{H, E, E, E,...

1

votes

4

answer

790

Views

### Pulling random files out of a folder for sampling

I needed a way to pull 10% of the files in a folder, at random, for sampling after every "run." Luckily, my current files are numbered numerically, and sequentially. So my current method is to list file names, parse the numerical portion, pull max and min values, count the number of files and multip...

0

votes

0

answer

14

Views

### Getting Error: SQLSTATE[42S22]: Column not found: 1247

My question refers to another discussion branch - MySQL select 10 random rows from 600K rows fast.
I have a simple one column table:
+-----------------------+
| keywords |
+-----------------------+
| Some text 1 |
| Some text 2 |
| Some text 3 |
| Some text...

1

votes

1

answer

109

Views

### Getting different results each time I run RandomForestRegressor

I use this code hoping to achieve determinism:
from sklearn.ensemble import RandomForestRegressor
np.random.seed(0)
import random
random.seed(0)
rf = RandomForestRegressor(n_estimators=1000, criterion='mse', min_samples_leaf=4)
But my results are not deterministic. Why is this, and how can I address...

1

votes

1

answer

29

Views

### Spectral Test in R

I would like to change my code in a way that 10000 points are placed in a [0,1]^2 plot. I tries changing 256 to 10000 but it generates weird placement. I should change the factors 137 and 187 but not sure how to change it. Anyone knows the logic behind?
Working sample:
nSim = 256
X=rep(0,nSim)
for (...

1

votes

2

answer

83

Views

### Generate random numbers where the difference is always positive

I am trying to generate some numbers, such that the difference is always positive. the user inputs the number of digits and the amount of rows they want. for example 3 digits 3 rows will produce
971
888
121
I want to make sure the difference of those is always positive. is there some kind of algorit...

1

votes

1

answer

36

Views

### dynamic number of columns in a data table with unique random draws

Suppose I have the following matrix, for arbitrary J:
set.seed(1)
J=2
n = 100
BB = data.table(r=1:n)
BB[, (paste0("a",seq(J))) := rnorm(n,1,7) ]
So the output is...
> BB
r a1 a2
1: 1 -3.38517668 -3.38517668
2: 2 2.28550327 2.28550327
3: 3 -4.84940029 -4.84940029
......

1

votes

1

answer

56

Views

### A difference between Seed and Rand.Seed

The golang docs says that
Seed, unlike the Rand.Seed method, is safe for concurrent use.
The rand.Seed is actually from math/rand package, but what is Seed? If Seed is another function then it's not present in math/rand so it's unclear from where that function comes from?
update:
I'm exploring the...

1

votes

1

answer

46

Views

### Why I can not find lowest mean absolute error using Random Forest?

I am doing Kaggle competition with the following dataset: https://www.kaggle.com/c/home-data-for-ml-course/download/train.csv
According to the theory, by increasing number of estimators in Random Forest model the mean absolute error would drop only until some number (sweet spot) and further increase...

1

votes

1

answer

107

Views

### R RF unbalanced classes low negative predicted value on unseen data compared to train

I have built a Random Forest model for predicting if a customer is doing operations regarding to fraud or not. It is a large an a quite unbalanced sample, with 3% cases of fraud, and I want to predict the minority class (fraud).
I balance the data (50% each) and build the RF. So far, I have a good m...

1

votes

0

answer

14

Views

### How to specify a random number generator in numpy

I'm building a monte carlo simulation using python, and have thus far been using numpy to generate my random variates. However, I've just learned that numpy uses the Mersenne Twister algorithm to produce its random numbers, which based on my limited understanding is not desireable in monte carlo sim...

0

votes

0

answer

2

Views

### Keyspace cardinaliy after using statistical randomness tests

I would like to know if there exists any algorithms to evaluate the cardinality of a keyspace containing only random keys ( given that the keys are tested for randomness by a statiscal test suite such as Diehard or Nist).
Such algorithm would accept as arguments the keylength and the test parameter...

1

votes

1

answer

55

Views

### not getting random values even with srand(time(NULL))

Even after including srand(time(NULL)) at the start of my function, (function is only called once in main) I get the same random value for r1 every time I run the program. r2 and r3 get random values fine, but I need random decimal values between 0.1 and 10.0 so what's wrong with the line containing...

1

votes

2

answer

218

Views

### What is the easiest way to generate a pseudo-random number in C for cryptographic purpose?

I need to generate random numbers for a student homework in cryptography.
At first I wanted to use
srand(time(NULL));
int r = rand();
But I read that shouldn't use it for cryptography.
I'd like if possible to not write my own pseudo-random number generator.
What is the fastest/easiest way to generat...

1

votes

2

answer

226

Views

### (PHP) Probability of two random strings be same

I have this code for generating random strings
public function random_string($length = 5)
{
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
return substr(str_shuffle($chars),0,$length);
}
So, is it possible that two generated strings can be same ?
In my case, there can be...