Click here to Skip to main content
15,887,175 members
Everything / Random

Random

random

Great Reads

by Igor Krein
A library of simple extension methods that could be useful for data generation tasks
by Peter Occil
Algorithms to turn biased "coin flips" into biased "coin flips", and how to code them.
by Kornfeld Eliyahu Peter
“Beware the Jabberwock, my son! The jaws that bite, the claws that catch! Beware the Jubjub bird, and shun The frumious Bandersnatch!” - LEWIS CARROLL
by Peter Occil
Python code for partially-sampled random numbers for accurate arbitrary-precision sampling

Latest Articles

by Alexey Shtykov
The thing that could generate pseudo random numbers faster than standard library does
by Member 4201813
How to calculate transition matrix for linear pseudo-random number generator manipulating its internal state
by Jack Devey
This post delves into the perplexing Monty Hall paradox, examining the probabilities associated with sticking or switching doors in the game scenario.
by ToughDev
How to allow only numeric input in TextBox

All Articles

Sort by Updated

Random 

12 May 2013 by 0867532
Vb.Net: how to generate random nuber, not including previos generaded???
12 May 2013 by 0867532
im trying to make thing,that generates random number, not includes previos(1-10)Public Class Form1 Dim NewTicketNumber As Integer Dim IsTicketDone1 As Boolean = False Dim IsTicketDone2 As Boolean = False Dim IsTicketDone3 As Boolean = False Dim IsTicketDone4 As Boolean...
14 Jul 2016 by Aamir Yousafi
Dear all, I have been through the forums and Google and have found only complicated setups for random number generators that are more advanced than rand(). My problem with rand() is that I can't seem to change the RAND_MAX, and even when I do by using #undef and #define followed by the integer...
12 May 2021 by Abeer Joshi
Yeah that helped me too, thanks everyone :)
17 Dec 2014 by Afzaal Ahmad Zeeshan
You need to make a use of the Random class, to generate Random numbers. But, that would give you a Random integer, you can then use those numbers to call different alphabets at those indices. You can read my previous article to create Random strings for URLs, instead of using them in URLs...
14 May 2014 by agent_kruger
How to get random unique numbers between any 2 numbers in c# without storing and checking the previous output?Please see the below link for an example:-https://adf.ly/msz2d[^]Thanks in advance
8 Aug 2013 by Ahmad Abd-Elghany
hello i want to generate a unique id just like this #OWD-716-46324 how can i achieve it
19 Feb 2024 by Alexey Shtykov
The thing that could generate pseudo random numbers faster than standard library does
30 Jan 2015 by Anthony Fountaine
You should seed the rand function once at the beginning of your code.srand(time(NULL));
30 Jan 2021 by Anuchen
I'm trying to develop a Java program which presents Users with encrypted word and asks them to decode it. Currently I present random words from an array after encrypting them with a random Caesar shift number. Could you please advise on how this...
12 Dec 2015 by Are Riff
#include #include #include using std::cout;using std::cin;using std::endl;using std::ostream;// Random value generator functiondouble randomize(const double &minVal, const double &maxVal){ std::random_device rd; std::mt19937...
9 Dec 2013 by ArunRajendra
I am not sure. Just give a try good luck.Random rnd1 = new Random();Gender g = (Gender)rnd1.Next(2);
11 Oct 2013 by ASP.NET Community
This is simple and effective method for generation of a random password Public Function GeneratePassword(ByVal PwdLength As Integer) As String   
16 Jul 2017 by Atlapure Ambrish
You can do something like this before your if condition. Call the below method to get the path and then check if the path exists, if not create the directory. public string GetTemporaryDirectory() { string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); ...
14 May 2014 by balajidileepkumar
namespace ConsoleEnum{ public class host { [STAThread] static void Main(string[] args) { List getrandom1 = Enumerable.Range(0, 100).ToList(); for (int i =0;i
9 Dec 2013 by BillWoodruff
The Enum you show is equivalent to:public enum Gender{ Male, Female}Here's an example of a method that will return either Gender.Male or Gender.Female at random:Random rand = new Random();private Gender randomGender(){ return (rand.Next(2) == 0) ? Gender.Male :...
5 Feb 2016 by BillWoodruff
The problem in your code is that you call 'CheckIfPrime passing it a 'BigInteger, but its parameter is: 'int.There's also a problem in that the Math library 'Sqrt Function will not accept Type 'BigInteger. You can work around that with this:BigInteger sqrt =...
29 May 2014 by BobJanova
This is a silly application, but presumably you know that. That algorithm's not useful for anything.Console and windowed desktop applications have somewhat different use paradigms, so it isn't so much a case of 'converting' as working out how your core algorithm should be presented in the...
23 Jul 2013 by BulletVictim
Good day all.Let me start by saying I am missing something obvious and I know, but cant seem to get it.I am working on a randomization application.I need to pull a list of active users(with USERID's) from my database, load them into a Datagridview, Well that works fine, now after that I...
24 May 2022 by CHill60
Look at the line random_char = random.choice(letters) + random.choice(numbers) + random.choice(symbols) For every iteration of the loop you are adding three characters to the array. You could change your loop to be something like for char in...
12 Aug 2014 by Coder93
I need to generate random latitude and longitude which is located in city (one city) for my application written in Java, how can I generate it?
11 Apr 2013 by CPallini
You don't need the if chains: you have arrays!For instance the choiche in whatList could be coded this way: var rwl = Math.floor((Math.random()*6)); // generate a random number between 0..5 (included) var whatChoice = whatList[rwl]; // use the random number to index the array.
13 May 2014 by CPallini
Short answer: you cannot.If you can, use a GUID for that.
2 Feb 2016 by CPallini
I would do the opposite, that is directly random generate a prime number. You know, under 10,000,000,000 there are 455,052,511 prime numbers (see How many primes are there?[^]) so you can randomlly choose r between 0 and 455,052,510 and then use the rth prime number. Possibly a pre-computed ...
14 Jul 2016 by CPallini
If you can use C++ then have a look at this page: random - C++ Reference[^].
9 Oct 2017 by CPallini
Quote: 51 - 99, but the problem says the range is 50-99. Indeed taht's the range. But, unfortunately 50 is even, hence 51 is the first valid entry of the requested range.
27 May 2018 by CPallini
Try #include /// need this for srand() -- for random numbers #include /// need this for time() -- time #include /// need this for cout> using namespace std; /// need this for cout> int main() { srand(time(0)); cout
7 Jan 2021 by CPallini
You are using the octal format specifier %o while you should use the decimal one %d. For example, the (decimal) number 50 becomes by 62 = 6*8+2 in octal representation. By the way, you know, you could write your program in a more compact way:...
3 May 2021 by CPallini
A very approach is by construction: Randomly generate the second (integer) number, say n2. Randomly generate an integer factor, say f. Let the first number, say n1, be equal to second number multiplied by the factor f (namely n1 = n2 * f)
18 Nov 2014 by Cryptonite
I keep reading articles on the web about how all random number generators on a computer are "pseudo" random, or "deterministic". Here I present an approach for nondeterministic number generation.
15 Feb 2015 by Dana Taha
I want generate 4 random name, type are Strings and put this random Strings without repeating to 4 Text Field in Java ?can you help me ? thank you ..
11 May 2017 by Dave Kreskowiak
If you're asking such a basic question you REALLY need to pickup a beginners book on C# and work through it. You need to assign the value to some other variable in order for anything to make sense and be usable. int result = int1 - int2;
17 Sep 2013 by DaveyM69
Have you had a look at this[^]?
8 May 2019 by Dechen Wangmo
I get new current list randomly but the randomly generated list should have TRUE in it, eg.['TRUE','FALSE' , 'FALSE', 'FALSE',] or ['FALSE' , 'FALSE', 'FALSE','TRUE'] import random list2 = ['TRUE','FALSE' , 'FALSE', 'FALSE', 'FALSE','FALSE','FALSE' ] current = [] def randompicker(): for...
12 Feb 2023 by Divya Ulasala
Examining the differences between java.util.Random, java.security.SecureRandom, and java.util.concurrent.ThreadLocalRandom to generate random numbers
14 Apr 2018 by dolfijn3000
so i'm working with perlin noise in c#. after experimenting with it i wanted to make a seammless perlin noise map. i want a map where the above edge of the map can continue in the bottom edge. is there someone that can help me with this ? What I have tried: searching the internet the only...
11 Apr 2013 by dteece1
In JS, I'm trying to make a random compliment generator using Arrays. The goal is that when the program is run, it takes a random part from each array and then displays the string. I'm sure i've used far too many variables here, but I am struggling. The variables at the top of the page...
11 Apr 2013 by E.F. Nijboer
Why not use the variables directly? The if statements aren't necessary. You might just want to check if the range of randoma/randomb is in the lower and upper boundary of the array:whatChoice3 = whatList[randoma];desChoice2 = descriptionList[randomb];Good luck!
5 Jan 2015 by eboolean
How to create Random e-mail adress for users' notifications in ASP.NET ?Like this;61e-2eb3af5-c7da98 -noreply@twitter.com
16 Sep 2013 by ellasaro
So I have this weird problem,I wrote a program in Visual Studio 2010.At first I configured it so the binary would have an icon, lets call it icon A. Then I changed the configuration again and changed the icon to icon B. The problem is that if I copy/move my binary to my desktop the...
14 May 2014 by Emre Ataseven
Guid creates random values but you can't set a range for them and they won't be numeric.Not an efficient way, also causes extra memory consumption but it may be useful if your range is relatively narrow.Create a list of int that starts with your small number till your big number....
6 Jul 2021 by Estys
Replace your return result; withreturn result.filter(x => x.length >= 3); Because the way you generate the combinations, you can't filter short combinations earlier. Cheers
11 Oct 2016 by F-ES Sitecore
Random numbers use what's known as a "seed" as the starting value to a mathematical equation that simulates randomness. If you give the random number generator the same seed you'll always get the same sequence of values, so the first number will always be the same. You can specify the seed in...
2 Nov 2015 by George Jonsson
Maybe try decimal.Parse or decimal.TryParse, if you want to continue on the road of string conversions.decimal pc = num * decimal.Parse(rand) / 100;
11 Apr 2019 by Gerry Schmitz
You should shuffle list2 in the "outer loop" (not before), if you want "combinations within combinations".
20 Feb 2023 by gggustafson
In this first part, we look at the random arrangement of numbers on a player's Bingo card.
27 Feb 2023 by gggustafson
Print_Cards to produce PDF file containing specified number of unique Bingo cards
26 Dec 2013 by Gitanjali Singh
Try thisprivate int RandomNumber(int min, int max){Random random = new Random();return random.Next(min, max); }Function Call int returnValue = RandomNumber(000000, 999999);
20 Nov 2022 by Graeme_Grant
Do you mean that you want a leading zero '0' for numbers less than 1? Then you would need: string ans = val.ToString("0.##"); If you want the same number of decimals, then: string ans = val.ToString("0.##0"); or... string ans =...
5 Jul 2021 by Greg Utas
I don't know Javascript but have a sense of what your code is doing. You're finding all combinations except for the empty string, which is a good start. But I see nothing in your code that filters out combinations of less than 3 letters. It looks...
28 Nov 2021 by Grelm
Hello, I'm making a number guessing game in C# for homework. When I run it, if the guess is lower or higher than the random number, it just loops "Guess higher" or guess lower". Any help would be appreciated. using System; namespace...
28 Nov 2021 by Grelm
Figured it out! static void Problem3() { Random random = new Random(); int numNums = 2; int GuessCount = 1; int current = 0; Console.WriteLine("Enter amount of numbers to guess...
7 Jan 2021 by GWLBSA
I am bored, and of course, when you're bored and know how to code, you just code whatever you can think of. I thought of making a die-rolling application, and the user can choose to roll anywhere from a 1 sided die to a 50 sided die. I tried out...
6 Jul 2021 by Happy kaul
0 I want to remove the single string and want to keep string with minimum length 3 and above i tried to access string with this if(result.string >= 3) but it is giving array length so i tried to access string but i cant. so please anybody who...
19 Jun 2013 by Hitesh Rohilla
I want to create a video with watermark change its position to corners every 2 minutes. i found this nice sourceAdding a dynamically positioned watermark to a video via ffmpegbut that don't work to create logo at random corner locations...all the four outputs in code mentioned in...
21 Oct 2019 by HitsugayaHisagi
Would like to ask, how do I generate 2 random numbers and then check if it is a prime? I would like to generate both and check them all in one click. I tried to write the code in C# but there are some invalid arguments. Here is my code.protected void btnstart_Click(object sender, EventArgs...
6 Feb 2016 by HitsugayaHisagi
So I've tried this code, and it works okay to me. Random rand = new Random(); BigInteger p = BigInteger.genPseudoPrime(128, 10, rand); txtP.Text = p.ToString(); Random rand2 = new Random(); BigInteger q = BigInteger.genPseudoPrime(128,...
9 Dec 2013 by IAmABadCoder
Hi, I have an enum called Gender and I was wondering how I would cast the enum to a random int between 0 and 1.public enum Gender : int{ Male = 0, Female = 1,}
29 Jul 2016 by Igor Krein
A library of simple extension methods that could be useful for data generation tasks
6 Jan 2022 by innapivov
Please help to write the C code Here is a version of a problem called the random walk. Assume that you`re very tired and dog leaves his lamppost on summer evenings and staggers randomly either two steps in the direction toward home or one step...
22 Nov 2014 by Ishpreet Kaur
The solution is:$var=rand($min,$max);if($var%3 == 0){echo "number is divisible by 3";}else{echo "number is not divisible by 3 and remainder is: ".($var%3);}
13 Jun 2023 by Jack Devey
This post delves into the perplexing Monty Hall paradox, examining the probabilities associated with sticking or switching doors in the game scenario.
28 Mar 2013 by johannesnestler
assuming your code is working - just change the scG.FillRectangles to (a looped) call to scg.DrawImage ...
14 May 2014 by johannesnestler
Hi Agen_Spock,It seems you are not getting it (concluded from your variouse comments)...If you don't store which numbers (of any set you wish your random numbers to come from e.g. 1-50) are already used, you can not know if the number is unique - Can you agree on that?So your whole...
6 Jan 2022 by KarstenK
Start with some Learn C tutorial. It wont be to hard if you can already code in some other language, but you need to respect the rules of C like a bunch of braces and declarations. Best is to write some functions and use struct. For some random...
28 Mar 2013 by kastriotlimani
Hi, i am a beginner at coding, and i am making a little game where a character is capturing some dots generated randomly.Now i need each dot to be an image (same image for all), but i cant find out how to do it.This is a piece of what I did:Rectangle[] rects;rects = new...
22 Feb 2016 by Keith Lewis
I'm new to coding, and just working on a little project to learn.I'm trying to produce multiple different versions of sets of attributes that I'll be inserting into a SQLite database.My current code prints the same numbers each time, ie:721213721213... etc.I guess...
26 Dec 2013 by ketan italiya
I want 6 digit random number,which shouldn't be repetative.number must is in between 000000 to 999999I mean it must contain 6 digits.i use this code for that.Random rnd = new Random(); int s = rnd.Next(000000, 999999);ingbal i =new ingbal(); i.Activation_Code =...
26 Dec 2013 by King Fisher
just use this:var chars = "0123456789";var random = new Random();var result = new string(Enumerable.Repeat(chars, 6).Select(s => s[random.Next(s.Length)]).ToArray());string random_num;password = result.ToString();
30 Oct 2017 by Kornfeld Eliyahu Peter
“Beware the Jabberwock, my son! The jaws that bite, the claws that catch! Beware the Jubjub bird, and shun The frumious Bandersnatch!” - LEWIS CARROLL
19 Dec 2017 by Lilyanaa
Hi, in this code I'm generate random number in specific range, but I want the out put of array must be l101 l101 l102 l104 I mean adding the word "host" to every number that is generate randomly, how can do this please?? I'm sorry about my bad english What I have...
15 Jun 2021 by lmoelleb
Learn to debug. It is simple, and the time investment pays of immediately. I understand that it might seem like "I have a lot to learn, so I will put that off and learn it later - for now I just want my program working", but that is a REALLY bad...
11 Mar 2016 by log98
For instance take a board with a form which moves from left to right and vice versa , i want this to be random. Actually, i want the landing of a ship to be random. Sample code that I wrote.I want to work only in the x-axis.public partial class theForm : Form { int xx; ...
3 Feb 2019 by Maciej Los
As far as i know OBS software is used for screen recording... So, all you need to do is to find software, which can: - convert images (ading effects), - display images from source folder in full-screen mode, - create slide show (in a specific amount of time) - etc. I'd recommend to use...
8 May 2019 by Maciej Los
Quote: You can use this syntax: if myItem in list: # do something Also, inverse operator: if myItem not in list: # do something It's work fine for lists, tuples, sets and dicts (check keys). Note that this is an O(n) operation in lists and tuples, but an O(1) operation in sets...
24 May 2022 by Manbir Singh 2022
I'm writing a code for Random Password generator where user should have an ability to select the length of password from pre-defined range (15,25) and code will generate random password using letters, numbers and symbols. If a user enters a...
18 Oct 2022 by Manojkumar-dll
Finally found it var result= "0"; if(Desired condition>0) { Random random = new Random(); double val = (random.NextDouble() * (max - min)...
20 Nov 2022 by Manojkumar-dll
I have written a code to generate random number ranging 0.8 - 1.2 while executing the numbers above 1 coming correctly as 1.2,1.22,1.4 etc but in the case of 0.xx its coming like .98,.89,etc I don't need repeating values tried with zeros...
18 Oct 2022 by Manojkumar-dll
I want to generate random float numbers ranging 0.0 to 1.5 and to store it inside a variable the values should store inside the variable under certain condition like in What have you tried? section apology for my poor explanation i tried my...
9 Oct 2017 by mappleleaf
Write code that generates a random odd integer (not divisible by 2) between 50 and 99 inclusive. Fill in the values of the sub-expressions labeled A, B, and C below. Random rand = new Random(); int n = rand.nextInt(A) * B + C; The answer is A = 25; B = 2; C =51 What I have tried: I dont...
17 Aug 2021 by Maskedllama
Hey everyone.I have made a code that renders 2 different random numbers on screen, but it justs keep updating the numbers. I want the program to stop updating those numbers once the first 2 appear on screen. Here is the code (I posted something...
17 Aug 2021 by Maskedllama
Hey everyone. Thank you for all the advices you gave me. I have been thinking about this issue, and I have rethought what I really want to do. It's my first "big" project, as you can imagine. Anyway, I need to display two random numbers on...
6 Aug 2013 by mbue
At the beginning i==0 therefore the value of check in the first do{}while loop is always false. The function runs in an infinite loop.to avoid this take a look: for(i=0;i
18 Aug 2021 by Mehrez Kanzari
I'm trying to generate random hexadecimal colors between this range: min= #00FF00 (green) and max= #FF0000 (red). What I have tried: I made my own search but I found only how to generate random hexadecimal colors not between two hexadecimal...
3 Jun 2013 by Member 10056564
I made a Bingo game and use a randomly generated set of 75 ball numbers for each new game.The array is public and is aryRnd(75). This works well for me and is reasonably fast.You can then use the array as needed in the project.Dim valueRnd As String = ""Dim ballCnt As Single =...
14 May 2014 by Member 10272815
Depending on your definition of random, this could work. To make it more random instead of using a fixed group size it could be randomly evalutated each pass through the loop. int[] GenerateRandom(int minimum, int maximum, int count) { int[] ret = new...
29 May 2014 by Member 10847268
Hello guys! I have this piece of code that I am willing to be converted to a windows forms application in c#!using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.ComponentModel;using System.Data;using System.IO;namespace Bruteforce{ ...
3 Aug 2014 by Member 10854414
I would like to split a rectangle in cells. In each cell it should be create a random coordinate (y, z). Unfortunately I can not attache pictures. Please see the pictures and my same question in another...
19 Nov 2014 by Member 11246689
we have a table of 50k items and we display it at search page with random sort and 10 items per page , and there is some filtersrandom with/without seed is very slownote that items are 3 category and first category should be display first with random order , then the second category with...
25 Nov 2014 by Member 11253513
How do i generate a random number in php
5 Dec 2014 by Member 11287540
I've been modifying the code for the past few day adding different things. I made my dice in a separate file to make sure they looked right then copied them over to my game, but when I try to call the functions in my game nothing happens. I don't even get a canvas. I'm not 100% sure what I"m...
7 Dec 2014 by Member 11287540
I've been working on this dice game for the past week adding a some stuff here and there. I got the game running then I added some drawings of dice for when there rolled to display on a canvas. I need a continue button to make the rest of the program run. I've looked at examples and I can't get...
18 Jul 2015 by Member 11846270
I have 4 balls that I am animating. But I want to animate all the 4 balls randomly within a time limit, say 1 minute. Since I want the balls to be independent of each other, I'm creating 4 storyboards (1 for each ball). But how can I call those storyboards RANDOMLY then? To be specific,...
2 Nov 2015 by Member 12108243
Alright so this is an in game command and it works perfect but I just can't figure out how to make decimal pc = num * rand / 100 because rand doesn't really define one number. internal class GambleCommand : Command { public GambleCommand() :...
2 Nov 2015 by Member 12108243
Alright I fixed it so I had to change it todecimal pc = decimal.Parse(rand) / num * 100;
24 Jan 2017 by Member 12324523
I need to generate images randomly on button click using c# private Image DrawText(String text, Font font, Color textColor, Color backColor){ //first, create a dummy bitmap just to get a graphics object Image img = new Bitmap(1, 1); Graphics drawing =...
13 Apr 2016 by Member 12355239
What's wrong in my code? I want to create function which will call a random numbers and multiple that or divide(in the random order). When I start the app, total result of multiplication(or division) is sometimes correct, but sometimes just equal 0.How should I solve the problem?What I...
14 May 2016 by Member 12523652
I need to create a RNG with specific "constants" and "equations"r(1== 0- a = 5- b = 1-Depending on the size of m, define; x, m, a, b as long (maximum of X: 5*2^k-1)" ^ " =...
21 Oct 2019 by Member 12696135
OK, Just throwing this out there... EASY PRIME GENERATION IN C#.NET I think this approach will be far more useful to most readers than some of the suggestions above. Forgive me, but after reading this thread I figured that this little trick is sorely missing from the discussion. I don't...
11 May 2017 by Member 13194839
Ok, so im making a math game where there is two random numbers that u need to subtract So im using a random int generator, and it defines 2 ints, Mathquestion1 and mathquestion2 it asks about what mathquestion1 - mathquestion2 is (mathquestion1 and mathquestion2 has a random number between 1 and...