473,567 Members | 2,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How random is random()?

Hey guys

Using Random(), how random is it, is it possible to be predicted? I have a
requirement for a very good random number generator. I was doing something
such as:

Random randomSeed = new Random((int)_se edTimer.Elapsed Ticks);
_random = new Random(randomSe ed.Next(0,99999 999));

return random.Next(min , max);

But i am finding that in some cases the same sets of numbers appear or
regularly occur? any idea why? Any tips on better methods for truly random
numbers?

Thanks

Jan 15 '07 #1
8 3899
"Daniel" <Da*****@vestry online.comwrote in
news:uO******** ******@TK2MSFTN GP03.phx.gbl:
Hey guys

Using Random(), how random is it, is it possible to be predicted? I
have a requirement for a very good random number generator. I was
doing something such as:

Random randomSeed = new
Random((int)_se edTimer.Elapsed Ticks); _random = new
Random(randomSe ed.Next(0,99999 999));

return random.Next(min , max);

But i am finding that in some cases the same sets of numbers appear or
regularly occur? any idea why? Any tips on better methods for truly
random numbers?

Thanks

Try looking into crypto stuff as they usually have much better random
number generation then standard windows/.net/etc.
Jan 15 '07 #2
Hi,
Try to find something random you can use to generate the seed!

Examples include

i) for a web server the sum of the last 100 unique IPs to access the
server
ii) get a user to move their mouse randomly and use some of the
captured points

etc

DANGEROUS COMMENT: as long as no one knows your seed, you should be
ok...
HTH,
James.

Daniel wrote:
Hey guys

Using Random(), how random is it, is it possible to be predicted? I have a
requirement for a very good random number generator. I was doing something
such as:

Random randomSeed = new Random((int)_se edTimer.Elapsed Ticks);
_random = new Random(randomSe ed.Next(0,99999 999));

return random.Next(min , max);

But i am finding that in some cases the same sets of numbers appear or
regularly occur? any idea why? Any tips on better methods for truly random
numbers?

Thanks
Jan 15 '07 #3
Thanks for replies,

Isn't that what i ddi, used a random seed? My first random number generates
a seed value from a random number seeded by elapsed ticks since server
started.....the n i use that randomseed to generate a random number between 0
and 99999999 to seed the next random number and then i tell that to find a
random number between my variables?

Why isn't that a random enough seeding strategy?

"pigeonrand le" <pi**********@h otmail.comwrote in message
news:11******** **************@ s34g2000cwa.goo glegroups.com.. .
Hi,
Try to find something random you can use to generate the seed!

Examples include

i) for a web server the sum of the last 100 unique IPs to access the
server
ii) get a user to move their mouse randomly and use some of the
captured points

etc

DANGEROUS COMMENT: as long as no one knows your seed, you should be
ok...
HTH,
James.

Daniel wrote:
>Hey guys

Using Random(), how random is it, is it possible to be predicted? I have
a
requirement for a very good random number generator. I was doing
something
such as:

Random randomSeed = new Random((int)_se edTimer.Elapsed Ticks);
_random = new Random(randomSe ed.Next(0,99999 999));

return random.Next(min , max);

But i am finding that in some cases the same sets of numbers appear or
regularly occur? any idea why? Any tips on better methods for truly
random
numbers?

Thanks

Jan 15 '07 #4
Hi,
In fairness, it should be ... but you said that the same numbers kept
coming up :0).

What range of numbers are you looking for?

James.

Daniel wrote:
Thanks for replies,

Isn't that what i ddi, used a random seed? My first random number generates
a seed value from a random number seeded by elapsed ticks since server
started.....the n i use that randomseed to generate a random number between 0
and 99999999 to seed the next random number and then i tell that to find a
random number between my variables?

Why isn't that a random enough seeding strategy?

"pigeonrand le" <pi**********@h otmail.comwrote in message
news:11******** **************@ s34g2000cwa.goo glegroups.com.. .
Hi,
Try to find something random you can use to generate the seed!

Examples include

i) for a web server the sum of the last 100 unique IPs to access the
server
ii) get a user to move their mouse randomly and use some of the
captured points

etc

DANGEROUS COMMENT: as long as no one knows your seed, you should be
ok...
HTH,
James.

Daniel wrote:
Hey guys

Using Random(), how random is it, is it possible to be predicted? I have
a
requirement for a very good random number generator. I was doing
something
such as:

Random randomSeed = new Random((int)_se edTimer.Elapsed Ticks);
_random = new Random(randomSe ed.Next(0,99999 999));

return random.Next(min , max);

But i am finding that in some cases the same sets of numbers appear or
regularly occur? any idea why? Any tips on better methods for truly
random
numbers?

Thanks
Jan 15 '07 #5
On Mon, 15 Jan 2007 13:14:07 -0000, "Daniel"
<Da*****@vestry online.comwrote :
>Hey guys

Using Random(), how random is it, is it possible to be predicted? I have a
requirement for a very good random number generator. I was doing something
such as:

Random randomSeed = new Random((int)_se edTimer.Elapsed Ticks);
_random = new Random(randomSe ed.Next(0,99999 999));

return random.Next(min , max);

But i am finding that in some cases the same sets of numbers appear or
regularly occur? any idea why? Any tips on better methods for truly random
numbers?

Thanks
You appear to have at least three PRNGs going, randomSeedm _random and
random, though the last might be a missing underscore. There is
nothing wrong with the principle of using randomSeed to generate seeds
for a set of further PRNGs, though it might be easier to just rely on
one PRNG for everything.

Without seeing the rest of your code I cannot tell why you are getting
the same set of numbers. One possibility is if min and max are too
close together then only a limited range of numbers can be returned.

If you are not happy with the standard C# PRNG, then there is the
cryptographic version:
System.Security .Cryptography.R andomNumberGene rator or
System.Security .Cryptography.R NGCryptoService Provider which both point
back to the CryptAPI RNG.

RFC 4086 describes the CryptAPI RNG thus:
"The Windows CryptAPI cryptographic service provider stores a seed
state variable with every user. When CryptGenRandom is called,
this is combined with any randomness provided in the call and with
various system and user data such as the process ID, thread ID,
system clock, system time, system counter, memory status, free disk
clusters, and hashed user environment block. This data is all fed
to SHA-1, and the output is used to seed an RC4 key stream. That
key stream is used to produce the pseudo-random data requested and
to update the user's seed state variable.

"Users of Windows ".NET" will probably find it easier to use the
RNGCryptoServic eProvider.GetBy tes method interface."

Note that this is a cryptographic RNG - there is no user definable
seed so you cannot generate the same set of random numbers twice.
SHA-1 is a cryptographic hash function and RC4 is a stream cypher,
which is in effect a very long period PRNG. Both are well covered in
Wikipedia if you are interested.

Alternatively you might want to write your own PRNG, then Chapter
Seven of "Numerical Recipes on C" is very helpful:
http://www.nrbook.com/a/bookcpdf.php

The code is in C and an example of the saying "Real programmers can
write Fortran in any language", but it is still a useful basis to work
from.

Knuth Volume Two is also useful for non-cryptographic PRNG background.

rossum

Jan 15 '07 #6
Hi Daniel,

the seed of your second random is directly dependent on the seed of the
first random. So, if you run this code several times with the same
ElapsedTicks, all the randoms will return the same sequence.
The parameterless constructor of random already generates a time dependent
seed, so that should do the same.Though I don't know the resolution it uses.

"Daniel" <Da*****@vestry online.comschri eb im Newsbeitrag
news:OZ******** ******@TK2MSFTN GP02.phx.gbl...
Thanks for replies,

Isn't that what i ddi, used a random seed? My first random number
generates a seed value from a random number seeded by elapsed ticks since
server started.....the n i use that randomseed to generate a random number
between 0 and 99999999 to seed the next random number and then i tell that
to find a random number between my variables?

Why isn't that a random enough seeding strategy?

"pigeonrand le" <pi**********@h otmail.comwrote in message
news:11******** **************@ s34g2000cwa.goo glegroups.com.. .
>Hi,
Try to find something random you can use to generate the seed!

Examples include

i) for a web server the sum of the last 100 unique IPs to access the
server
ii) get a user to move their mouse randomly and use some of the
captured points

etc

DANGEROUS COMMENT: as long as no one knows your seed, you should be
ok...
HTH,
James.

Daniel wrote:
>>Hey guys

Using Random(), how random is it, is it possible to be predicted? I have
a
requirement for a very good random number generator. I was doing
something
such as:

Random randomSeed = new
Random((int)_ seedTimer.Elaps edTicks);
_random = new Random(randomSe ed.Next(0,99999 999));

return random.Next(min , max);

But i am finding that in some cases the same sets of numbers appear or
regularly occur? any idea why? Any tips on better methods for truly
random
numbers?

Thanks


Jan 15 '07 #7
Take a look at http://www.random.org/. I am pretty sure that they have a web
service which returns really random numbers.
Ethan
"Daniel" <Da*****@vestry online.comwrote in message
news:uO******** ******@TK2MSFTN GP03.phx.gbl...
Hey guys

Using Random(), how random is it, is it possible to be predicted? I have a
requirement for a very good random number generator. I was doing something
such as:

Random randomSeed = new Random((int)_se edTimer.Elapsed Ticks);
_random = new Random(randomSe ed.Next(0,99999 999));

return random.Next(min , max);

But i am finding that in some cases the same sets of numbers appear or
regularly occur? any idea why? Any tips on better methods for truly random
numbers?

Thanks

Jan 15 '07 #8
After more searching i discovered i was seeding my numbers inside the method
that called them. I am not getting the same numbers over and over just
sometime si get a sequence repeated. Apparently if your range is small and
you call it often its possible i can seed with the same number twice.

Thanks for the ideas, especially the crypto method i will investigate that
further.

Thanks to all the replies
"Ethan Strauss" <ethan dot strauss at Promega dot comwrote in message
news:ON******** *****@TK2MSFTNG P04.phx.gbl...
Take a look at http://www.random.org/. I am pretty sure that they have a
web service which returns really random numbers.
Ethan
"Daniel" <Da*****@vestry online.comwrote in message
news:uO******** ******@TK2MSFTN GP03.phx.gbl...
>Hey guys

Using Random(), how random is it, is it possible to be predicted? I have
a
requirement for a very good random number generator. I was doing
something
such as:

Random randomSeed = new Random((int)_se edTimer.Elapsed Ticks);
_random = new Random(randomSe ed.Next(0,99999 999));

return random.Next(min , max);

But i am finding that in some cases the same sets of numbers appear or
regularly occur? any idea why? Any tips on better methods for truly
random
numbers?

Thanks


Jan 15 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
3662
by: Paul Rubin | last post by:
http://www.nightsong.com/phr/python/sharandom.c This is intended to be less predicable/have fewer correlations than the default Mersenne Twister or Wichmann-Hill generators. Comments are appreciated.
5
1480
by: Bill | last post by:
Hello, If I type the following code directly into the interpreter, it works. If I run it from a script, it generates the following error. Can someone help? Thanks! ------------------------ import random for i in range(10):
10
2490
by: Marshall Belew | last post by:
I'm trying to synchronize a network app that uses random numbers generated by System.Random. Rather than pass every randomly generated number, I just pass the seed. I'm seeing a result that leads me to believe that a seeded random number is still slightly random. I need a predictable random number. Here's my results Machine 1 Seed:...
4
2739
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is...
2
2197
by: Brendon Towle | last post by:
I need to simulate scenarios like the following: "You have a deck of 3 orange cards, 5 yellow cards, and 2 blue cards. You draw a card, replace it, and repeat N times." So, I wrote the following code, which works, but it seems quite slow to me. Can anyone point out some obvious thing that I'm doing inefficiently? Or, is this more or...
6
2117
by: Pao | last post by:
My code works in this way: I declared a static array in a class (public static int GVetRandom = new int;) that in a for cycle I fill with random numbers. The array gets cleared (clear method) and refilled at each turn of cycle. On my developing pc, the same sequence of random numbers was repeated from on turn of cycle to the other; I put...
6
4801
by: Mike Langworthy | last post by:
i can not seem to get this code to work. someone please help using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program {
15
2715
by: caca | last post by:
Hello, This is a question for the best method (in terms of performance only) to choose a random element from a list among those that satisfy a certain property. This is the setting: I need to pick from a list a random element that satisfies a given property. All or none of the elements may have the property. Most of the time, many of the...
4
11533
by: globalrev | last post by:
do i need to import something to use random?
11
11539
by: Alex | last post by:
Hi everybody, I wonder if it is possible in python to produce random numbers according to a user defined distribution? Unfortunately the random module does not contain the distribution I need :-( Many thanks axel
0
7688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7590
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7905
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7960
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6272
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5488
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3648
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3630
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.