473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

random numbers in c#

how do i make the random function be seeded by the timer? from the
complete lack of any resources on the web dealing with this i'm
assuming this is an extremely nontrivial problem. is there some magical
new technique for randomization that just makes no use of random
numbers? something specific to dot net.

Nov 17 '05 #1
3 1425
David,

You can just create a new instance of the Random class, with the default
constructor. It will seed the random number generator with the value
returned from the static TickCount method on the Environment class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"david bandel" <Sh*******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
how do i make the random function be seeded by the timer? from the
complete lack of any resources on the web dealing with this i'm
assuming this is an extremely nontrivial problem. is there some magical
new technique for randomization that just makes no use of random
numbers? something specific to dot net.

Nov 17 '05 #2
Dear Mr. Bandel,

Do you know of www.google.com ?

http://www.google.com/search?hl=en&q=random+.net+seed gives many relevant
results on the very first page, so talking about "complete lack of resources
on the web" is pointless.

"david bandel" <Sh*******@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
how do i make the random function be seeded by the timer? from the
complete lack of any resources on the web dealing with this i'm
assuming this is an extremely nontrivial problem. is there some magical
new technique for randomization that just makes no use of random
numbers? something specific to dot net.

Nov 17 '05 #3
david bandel <Sh*******@gmail.com> wrote:
how do i make the random function be seeded by the timer? from the
complete lack of any resources on the web dealing with this i'm
assuming this is an extremely nontrivial problem. is there some magical
new technique for randomization that just makes no use of random
numbers? something specific to dot net.


No, I think there's a lack of resources on the web because it *is*
trivial :)

From the docs for the parameterless constructor for System.Random:
<quote>
Initializes a new instance of the Random class, using a time-dependent
default seed value.
</quote>

Alternatively, use the version which is given an int, and generate that
from the timer in whatever fashion you want.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4

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

Similar topics

21
by: Marc Dansereau | last post by:
Hi all I am new to this forum and to the c programming language. If I understand, the random() function in C return numbers that follow a uniform distribution U(0,1). Can somebody know how to...
104
by: fieldfallow | last post by:
Hello all, Is there a function in the standard C library which returns a prime number which is also pseudo-random? Assuming there isn't, as it appears from the docs that I have, is there a...
12
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's...
13
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000,...
24
by: pereges | last post by:
I need to generate two uniform random numbers between 0 and 1 in C ? How to do it ? I looked into rand function where you need to #define RAND_MAX as 1 but will this rand function give me ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...

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.