I'm working in Microsoft Visual C# 2008 Express.
I found this snippet of code:
public static int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
the problem is that I've run it more than 100 times, and it's ALWAYS giving me the same answer when my min = 0 and...
Can you tell me any ways to generate non-uniform random numbers?
I am using Java but the code examples can be in whatever you want.
One way is to create a skewed distribution by adding two uniform random numbers together (i.e. rolling 2 dice).
...
I'm just diving into some C++ and I decided to make a random number generator (how random the number is, it really doesn't matter). Most of the code is copied off then net but my newbie eyes cannot see anything wrong with this, is there any way this can be tweaked to give a number other than "6" each time?
#include <iostream>
#include <...
I am trying to generate a random integer for each row I select between 1 and 60 as timer.
SELECT downloads.date, products.*, (FLOOR(1 + RAND() * 60)) AS timer
I have searched and keep coming up to this FLOOR function as how to select a random integer in a range. This is giving me a 1 for every row.
What am I missing?
I am on mysql ...
How can I make it so the same sequence of random numbers come out of an MSVC++ program and a C# .NET program?
Is it possible? Is there any relationship between MSVC++ rand() and System.Random?
Given the example below it seems they are totally different.
#include <iostream>
using namespace std;
int main()
{
srand( 1 ) ;
cout <<...
I'm writing a vertex shader at the moment, and I need some random numbers. Vertex shader hardware doesn't have logical/bit operations, so I cannot implement any of the standard random number generators.
Is it possible to make a random number generator using only standard arithmetic? the randomness doesn't have to be particularly good!
...
declare @fieldForceCounter as int
declare @SaleDate as dateTime
declare @RandomNoSeed as decimal
set @fieldForceCounter = 1
set @SaleDate = '1 Jan 2009'
set @RandomNoSeed = 0.0
WHILE @fieldForceCounter <= 3
BEGIN
while @SaleDate <= '1 Dec 2009'
begin
INSERT INTO MonthlySales(FFCode, SaleDate, SaleValue) VALUES(@fie...
Hello!
I heard that PHP's rand() function doesn't give good random numbers. So I started to use mt_rand() which is said to give better results. But how good are these results? Are there any methods to improve them again?
My idea:
<?php
function rand_best($min, $max) {
$generated = array();
for ($i = 0; $i < 100; $i++) {
...
I am looking for an efficient way to generate numbers that a human would perceive as being random. Basically, I think of this as avoiding long sequences of 0 or 1 bits. I expect humans to be viewing the bit pattern, and a very low powered cpu should be able to calculate near a thousand of these per second.
There are two different con...
All I want is a pragmatic random number generator in C# so I can say e.g.
int dummyAge = MathHelpers.GetRandomNumber(20,70);
and have it seem quasi random, e.g. to generate dummy data.
Most stack overflow questions on this topic and on the web get into a philosophical discussions on true randomness which is not what I'm interested a...
What is a good random number generator to use for a game in C++?
My considerations are:
Lots of random numbers are needed, so speed is good.
Players will always complain about random numbers, but I'd like to be able to point them to a reference that explains that I really did my job.
Since this is a commercial project which I don't h...
How can I generate a random hexadecimal number with a length of my choice using C#?
...
For 6 years I've had a random number generator page on my website. For a long time, it was the first or second result on Google for "random number generator" and has been used to decide dozens, if not hundreds of contests and drawings on discussion forums and blogs (I know because I see the referrers in my web logs and usually go take a ...
I have a very simple iPhone app that requires a random integer from 1-100.
I have a button that calls the random number function then displays it.
-(IBAction)buttonReleased;
{
srandom(time(NULL));
int theNum = random() % 100 + 1;
numberDisplay.text = [NSString stringWithFormat:@"%d", theNum];
}
The problem is, if I press...
I'm not asking if these are truly random. I just wanted to know if two users hit the a page at the same time can they get the same random number? I'm thinking if i run this on a multicore server will i generate the same randon number a good amount of time due to syncing or whatever other reasons?
public static class SBackend
{
stati...
My current task is to optimise a Monte Carlo Simulation that calculates Capital Adequacy figures by region for a set of Obligors.
It is running about 10 x too slow for where it will need to be in production and number or daily runs required. Additionally the granularity of the result figures will need to be improved down to desk possib...
Hi,
in my previous post I was asking how to generate numbers following a normal distribution.
Since I have also other distributions to generate and I saw 3 libraries might provide them (GSL, TechnicalReport1(doc link?), Boost), I was wondering which one you would choose.
As a side note: the reference platform for my application is a ...
Original Question:
I want to generate a Poisson process. If the number of arrivals by time t is N(t) and I have a Poisson distribution with parameter lambda how do I generate N(t)? How would I do this in C++?
Clarification:
I originally wanted to generate the process using a Poisson distribution. But, I was confused about what paramet...
So far I've been using the C# Mersenne Twister found here to generate random numbers:
http://www.centerspace.net/resources.php
I just discovered SFMT which is supposed to be twice as fast here:
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/
Can anyone point me at a C# implementation of SFMT?
My requirements are to generate an...
I am writing some embedded code in C and need to use the rand() function. Unfortunately, rand() is not supported in the library for the controller. I need a simple implementation that is fast, but more importantly has little space overhead, that produces relatively high-quality random numbers. Does anyone know which algorithm to use or s...