View previous topic :: View next topic |
Author |
Message |
flw Forum Fanatic
Joined: 27 May 2002 Posts: 16777215 Location: U.S.A.
|
Posted: Mon Feb 03, 2003 5:33 am Post subject: language for random number generator |
|
|
I'm playing with a routine and I need to have a random number generator that can use the date and time to create the random number. Therefore the pattern could never be duplicated easily without the exact date and time to the second of the computation.
What language(s) can use both date and time together?
|
|
Back to top |
|
|
myhatisred Just Arrived
Joined: 11 Jan 2003 Posts: 0
|
Posted: Mon Feb 03, 2003 5:36 am Post subject: |
|
|
for what platform?? almost any language can do that. I'd say C/C++ would be the easiest
|
|
Back to top |
|
|
Wombat Trusted SF Member
Joined: 24 Apr 2002 Posts: 0 Location: Canberra
|
Posted: Mon Feb 03, 2003 6:50 am Post subject: |
|
|
A lot of languages already have a function to generate random numbers from date and time, just like you need. In Visual Basic the random number generator function is Rnd(), and there's also the Randomize statement to reset the generator's seed to the current system date/time.
Last edited by Wombat on Mon Feb 03, 2003 11:41 pm; edited 1 time in total |
|
Back to top |
|
|
flw Forum Fanatic
Joined: 27 May 2002 Posts: 16777215 Location: U.S.A.
|
Posted: Mon Feb 03, 2003 3:00 pm Post subject: |
|
|
It was my understanding that most were set by time and not by date as well. Is this incorrect?
Also some are coded so that they are closer to being random than others.
Is this incorrect?
Thanks
|
|
Back to top |
|
|
myhatisred Just Arrived
Joined: 11 Jan 2003 Posts: 0
|
Posted: Mon Feb 03, 2003 3:38 pm Post subject: |
|
|
most of the high-level languages are completely random #s there's no formula to really figure them out.
|
|
Back to top |
|
|
flw Forum Fanatic
Joined: 27 May 2002 Posts: 16777215 Location: U.S.A.
|
Posted: Mon Feb 03, 2003 8:31 pm Post subject: |
|
|
Quote: |
most of the high-level languages are completely random #s there's no formula to really figure them out. |
Which is why my quesiton is which languages will or already do use date as well as time for generation. i.e. It is my understanding that java just uses time only. This may be wrong but that's why I'm asking.
[/quote]
|
|
Back to top |
|
|
myhatisred Just Arrived
Joined: 11 Jan 2003 Posts: 0
|
Posted: Mon Feb 03, 2003 8:39 pm Post subject: |
|
|
I'm almost positive that C/C++ uses date and time
|
|
Back to top |
|
|
decypherohm Just Arrived
Joined: 16 Nov 2002 Posts: 1 Location: World - Europe - Portugal - Lisbon
|
Posted: Mon Feb 03, 2003 11:32 pm Post subject: |
|
|
Is there any randomizer for pascal?!?!?!
|
|
Back to top |
|
|
myhatisred Just Arrived
Joined: 11 Jan 2003 Posts: 0
|
Posted: Mon Feb 03, 2003 11:35 pm Post subject: |
|
|
i don't know pascal but there's some sort of random # generator for all languages
|
|
Back to top |
|
|
Wombat Trusted SF Member
Joined: 24 Apr 2002 Posts: 0 Location: Canberra
|
Posted: Mon Feb 03, 2003 11:41 pm Post subject: |
|
|
I had a dig through MSDN and it turns out that by default Visual Basic uses the number of seconds elapsed since midnight as the seed. Not as random as I would have liked!
However, you can choose to give the Randomize statement a number to use as the seed. You could easily add the current system date and time to use as the seed. This would probably give you what you want:
Code: |
Dim MySeed
Dim MyRandomNumber
MySeed = Date + Time
Randomize MySeed
MyRandomNumber = Int((100 * Rnd) + 1) ' Generates random value between 1 and 100. |
|
|
Back to top |
|
|
ToddK Just Arrived
Joined: 29 Nov 2002 Posts: 0 Location: Ottawa, Canada
|
Posted: Tue Feb 04, 2003 12:34 am Post subject: |
|
|
VB's random is pretty non-random. Totally sucky.
A good method is to use a GUID.
|
|
Back to top |
|
|
vlad902 Just Arrived
Joined: 04 Jan 2003 Posts: 0
|
Posted: Tue Feb 04, 2003 2:19 am Post subject: |
|
|
OpenBSD for true random ness! Best way I say to make a random number is to multiply a couple of random numbers, then multiply them by the time and date (so if it's 4:22 it's multipled by 4 and then 22) and that will make it pretty god damn random
|
|
Back to top |
|
|
tutaepaki Trusted SF Member
Joined: 02 May 2002 Posts: 3 Location: New Zealand
|
Posted: Tue Feb 04, 2003 2:36 am Post subject: |
|
|
http://triumvir.org/rng/
For lots of links to discussions of Random numbers and some of their
dubious randomness. It includes plenty of samples too.
|
|
Back to top |
|
|
|