Most voted "random" questions
Use this tag for questions pertaining to random or pseudo-random numbers.
Learn more…236 questions
Sort by count of
-
3
votes1
answer199
viewsHow to randomly shuffle an Array in Ruby?
I would like to have the items in an array shuffled. Something like this: [1,2,3,4].scramble => [2,1,3,4] [1,2,3,4].scramble => [3,1,2,4] [1,2,3,4].scramble => [4,2,3,1] and so on,…
-
3
votes3
answers88
viewsProblem receiving random integer values in array
Eclipse does not point out any errors in the code, but does not execute. package gerarOrganizar; import java.util.Random; public class GerarOrganizar { public static void main(String[] args) { int…
-
3
votes3
answers10600
viewsGenerate random data within a range
I cannot return any number. Ex: If I use "lower 1500" and "higher 5000", I would appear in this interval if I did not enter the while, only nothing is returning. public int aleatoriar(int maior, int…
-
3
votes1
answer122
viewsError using Random in JAVA
When I run this code: public class main { static boolean terminar = false; public static void main(String[] args) { long init = System.currentTimeMillis(); BruteForce(true, true, "a123", 10, 10000);…
-
3
votes3
answers3097
viewsHow to generate random matrices without repeating numbers on the same line?
I want to store random numbers from 1 to 60 in an array. When there are equal numbers on the lines, it is to generate another random number. Type, cannot be: 11 55 55 43 49 30, and yes should be 11…
-
3
votes1
answer191
viewsHow to get really random numbers with 'Rand()' in C?
For a schoolwork, I need to create a game, for which I need to generate a random number to make it fair. In one case, as I will post below, I need to assign a random number between 0 and 2 to modify…
-
3
votes1
answer222
viewsRandom site theme with exchange every 30min
I am needing my site to change the theme randomly every 30 min. So the logic would be: User enters the site now and views it in blue color (which is the default), but if this same user comes back in…
-
3
votes1
answer431
viewsWhy does ORDER BY RAND() slow down the query? Is there another alternative?
I had just asked questions regarding the ordering of random values through the MYSQL. From there I began to notice an uncomfortable slowness in the suggested system of friendships here of the…
-
3
votes1
answer504
viewsMysql select Random with priorities
I have the following scenario, I have a table and I need to select an order by RAND(). But I would like to put some conditions for example: TABELA ID | NOME | IDADE | GRUPO Dice 1 | Hiago | 20 | 1 2…
-
3
votes4
answers3023
viewsRand between numbers with comma
How to generate a number float between two numbers? Ex.: A random number between -270.33 and -47.5.
-
3
votes1
answer198
viewsDo not repeat letters (char) in an ASCII matrix
You had to create a 5x5 array by printing random characters from the ASCII table. public class ExercicioClass01g { static Scanner ler = new Scanner(System.in); public static char mat[][] = new…
-
3
votes1
answer43
viewsRandomize images as textures in 3D solids
Good, I have 30 solids and I have a different image for each of them. I created one array for the images, and if you choose to use the same image at all (as I left here in the code, use the bandeira…
-
3
votes2
answers1609
viewsRandom distribution in lists with python
I have a list: li = [0, 0, 2313, 1221, 0, 1333, 66, 0, 0, 0, 0] and another list of lists, where: The list of lists is called disciplines (below). The lists that are within disciplines, are also…
-
3
votes3
answers1435
viewsHow do I generate a random negative number?
I cannot generate a random number that is negative, for example less than 0
-
3
votes1
answer637
viewsRandom value in C++
I was practicing a little C++, I created that simple data game exercise, so I came across a problem, how can I generate random values in C and C++? Taking a look at the site (c plus) I found an…
-
3
votes1
answer10220
viewsGenerate random numbers in C?
I need to generate 5 random numbers in a range between -10 and +10. How could I do this ? I’ve seen that one can use shuffle, malloc or even realloc, but being new in C, I don’t quite understand how…
-
3
votes1
answer240
viewsRandom from 1 to 500 without repeating
I have a table in the database with ids from 1 to 500, each time the page is updated a number drawn appears and I make a select and display a message that is in the selected id, but I would like…
-
3
votes1
answer65
viewsproblem with Random.radint(1, 6) and if conditional
Friends, I am starting out in programming, so I apologize if it is too banal my question. My guess is that something happens in the if string, because never the winning message is read, the program…
-
3
votes1
answer607
viewsDoubt with Random in c++14 and 17
I was searching the Internet for how to do pseudo-random numbers in c++ and all the examples I found were with the srand function, but in some places people said srand is from c, and c++ already has…
-
3
votes1
answer563
viewsProgram to generate games and numbers of the mega sena
Unfortunately I’m not managing to generate more than a set of 6 numbers. The correct one would be to generate the amount of games that the user would type and would be stored in the variable jogos.…
-
3
votes1
answer303
viewsWhat is the difference between Random.Choice and Random.Choices in Python?
I know they both draw random numbers, but what’s the difference between them ?
-
2
votes2
answers1792
viewsGenerate random number with date value and current time with Javascript
I would like to know how to generate a random number, based on the current date and time value, using Javascript. I couldn’t get a real example to show here, because I really don’t know how to do…
-
2
votes2
answers774
viewsGenerating random number in C language
Let’s assume I have an empty array of size 8. int A[8]; And then I intend to fill it with random values whose I would have a function similar to the rand(); However, I call on rand() for each…
-
2
votes2
answers2082
viewsGenerate random numbers from a predefined set
How to generate a random number in a range of non-sequential numbers. For example, a function that randomly chooses between the values, 3, 10, 20 and 2334 in the language C
-
2
votes2
answers7781
viewsGenerate random number without repetition in C
Hello, I am making a memory game in c, and would like to know how to generate a random number without repetition. I will post what in the function so far. I will need to do another function only to…
-
2
votes1
answer349
viewsList of random numbers without repetition Android
I have an Arraylist with N items inside and I need to randomly group them into 2 sets of X items and the rest into another set. But none of them can repeat themselves. For example: my Arraylist has…
-
2
votes1
answer12084
viewsRandom letters: How to generate with Rand and how to compare them in C
I’m trying to create a char vector of 10 positions, I want to feed it with 10 random letters and sort down with Bubble Sort. My question is: does Rand generate random characters as well as generate…
-
2
votes2
answers835
viewsHow not to repeat random numbers?
I am creating a rotary banner, and for this I use the javascript rule that draws a position in the array and displays, this already works well, the problem is that sometimes draws the same number in…
-
2
votes2
answers145
viewsError compiling code with import java.util.Random; Random.nextInt()
I’m studying the Java programming language and I found an obstacle, by some chance I can not compile this code import java.util.Random; public class Random { public static void main(String[] args){…
-
2
votes2
answers1180
viewsDrawing of numbers with exception
How do I draw lots n of numbers in C language where I can exclude the possibility of drawing a certain number from my range given a certain condition? Exemplifying in code: #include <stdio.h>…
-
2
votes2
answers1192
viewsMaximum value for srand((unsigned)time(NULL);
I was reading about the random numbers not being so random and I saw that one way out was to feed a seed with the srand((unsigned)time(NULL) ); To make tests I generated a vector of 100,000…
-
2
votes2
answers2470
viewsHow to use Python Random.Seed()?
I need to generate a random number using the Python language, in the documentation saw that there is a function random.seed() to increase the randomness of the generated number, but I found very…
-
2
votes1
answer159
viewsDistributing points evenly in a circle
I started to make a code to randomly distribute points evenly in a circle, but by generating a point located with a random theta angle between 0 and 2π and with a distance from the center of the…
-
2
votes2
answers930
viewsRandom number between 0 and 8, except 5, in Javascript using Math.Random
Hello, using Javascript, I need to generate a random number between the 0 and 8, however the number 5 cannot be one of those numbers generated. I am returning these numbers so far using the…
-
2
votes1
answer56
viewsHow to take only one value of a Random variable and turn it into a constant?
How do I get only one value from a variable you use Random and store in another variable? It is possible? Wanted to store what will appear to the user int cartaUnoPersonagem = new…
-
2
votes4
answers3505
viewsHow to generate random characters or string?
How to specify the number of times a character can repeat? Ex: I have ABC, where C should repeat 4 times in a new string 6-character: ( AB CC CC ) or (AC CB CC) or ( AC CC CB ) To can only enter…
-
2
votes2
answers381
viewsOptimization, speed in select, and PHP code
Following the reasoning of this question, i made this method, where I select several users at once to return me only 1 in random order, ie, my query that is in the function does a scan on the whole…
-
2
votes1
answer87
viewsConsistency in Python results
Hello, I’m studying python code and I came across this line: np.random.seed(0) where it says consistency of results. I searched, but I still can’t understand the function of this command. Could…
-
2
votes1
answer249
viewsHow to ignore certain elements in a list that will go through a random process? (pending)
This program finds 3x3 magic squares by brute force and prints automatically when it encounters a. code: import random vetor = [1, 2, 3, 4, 5, 6, 7, 8, 9] def magicsquare(): return…
-
2
votes1
answer216
viewsWhen I create a function in C++ do the variables within it stay in memory?
When I was studying pseudocode, I learned that when you call a function and create a variable, it only "exists" when I call that function, for example. funcao teste(): x = 10 retorna x In case, when…
-
2
votes1
answer340
viewsPython : 'int' Object is not iterable Random function
I’m having this mistake when I run the code. If I define pos=(algum numero qualquer) code runs normally ,but if I use this error function. 'int' Object is not iterable in line 20 at first. Where am…
-
2
votes2
answers196
viewsCode to generate random number sequence does not work
I developed a C code to generate a sequence of random numbers to be typed by the user, but it’s the first time I make a source code of the type for a college job, and according to the research I did…
-
2
votes1
answer32
viewsReturn the elements of a randomized list
I have an array generated by a string.split(), and the value of this string is obtained by a input. That is to say: string = input("Digite os Nomes separados por Vírgula") arrTeste =…
-
1
votes1
answer341
viewsFunction RANDOM in IBM Informix BD?
I need to use an Random() SQL function in a Informix version 11.50 database. But in select below returns syntax error : select random(), codigo from minha_tabela; 674: Routine (random) can not be…
-
1
votes2
answers1167
viewsHow to generate Math.Run from a value other than 0?
Hey guys, I just got to know the Math.Andom method and I already know how to generate values from 0 to another number through multiplication, e.g.: Math.Random()*20. But I’m wondering how I can do…
-
1
votes1
answer2518
viewsCreate function that returns random numbers in C
I need to create a function that returns random numbers without repetition between 2 intervals. I wanted to create a kind of a card game, where the cards are shuffled, and when they return they…
-
1
votes2
answers83
viewsProblem with random values
Good night, you guys. I’m solving an exercise where I must, at each run, generate a random number and then turn it into a letter. For this I made a function. It is almost all right, the number is…
-
1
votes3
answers2472
viewsGenerate single random value with php
I need to generate a random value with letters and numbers in PHP, always starting with the letter A and having numbers and letters mixed with the value. Refers to the "control code" field contained…
-
1
votes2
answers2945
viewsGenerate a word between defined words [PHP]
I’m pretty new at PHP, but I already know the basics of HTML, and a large part of Ruby script (nay ruby on rails). Well, you know, how can I generate a word or something random, you might say, but…
-
1
votes1
answer69
viewsSimplify Probability function with priority
I have this function that works as I want. It takes a value between -2 and 2 to set the priority to choose between two strings. My point is: How can I simplify the function? function…