Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 2nd, 2006, 12:09 PM   #1
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
[vb6] need advice concerning a largescale non-recurring random number generator

i'm trying to come up with a pseudo random-number generator that will not generate duplicate numbers.

this number generator will generate a series of numbers. it can be 10 random numbers, or it could be well over 10000.

to make a NG for the smaller end of the spectrum (10) is no big deal; i'd just run a for() loop to check newly generated values against those previously stored in an array. it's when i have to generate 1000+ numbers that i fear i'm going to have memory issues on older machines.

i don't think a for() loop is going to cut it. can anyone give me some advice on how to go about making a memory-efficient, largescale random number generator?

i think i read somewhere that you could use the current time to come up with continuously unique numbers or something. don't remember where i read it or what the details were. might this be relevant?

thanks
chepfaust is offline   Reply With Quote
Old Jun 2nd, 2006, 12:19 PM   #2
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
Why in the world would you need a prng that doesn't repeat any values?
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials.
--WilliamSChips on Slashdot
uman is offline   Reply With Quote
Old Jun 2nd, 2006, 12:39 PM   #3
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
because the generated numbers are going to be appended to filenames, where the number is going to be the only unique part of the filename.

File1092343.txt
File3423498.txt
File2342342.txt
...

and so on. i can't have two "File1092343.txt" outputs.
chepfaust is offline   Reply With Quote
Old Jun 2nd, 2006, 4:07 PM   #4
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
why do they have to be random? Why not just do
1.txt
2.txt
3.txt
etc.
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials.
--WilliamSChips on Slashdot
uman is offline   Reply With Quote
Old Jun 2nd, 2006, 7:16 PM   #5
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
That's the way they already are. The whole point of the program is to randomize them.
chepfaust is offline   Reply With Quote
Old Jun 7th, 2006, 4:56 PM   #6
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
solution?

well, here's what i ended up doing.

i ended up having to limit the total number of generated numbers to 899, but i came up with (what i think is) a rather efficient way of generating 899 pseudo-random non-recurring numbers.

first i generate a list of three-digit sequential numbers. (i started with 100 because i didn't feel like messing with the number formatting to create values like 001. the fact that i started with 100 is also the reason i can only generate 899 numbers, instead of 999.)

100.txt
101.txt
...
349.txt
...
666.txt

then i add a certain number of random digits to the front of the sequential numbers. since everything in the sequential number list is already a unique value, it doesn't matter if i make duplicate numbers with my random number routine.

my output ends up looking like

456100.txt
642101.txt
...
265349.txt
...
478666.txt

and i can have values like

884201.txt
884202.txt

without breaking anything.

if coded correctly, both of these operations can be performed within the same loop, thus eliminating the need to waste time comparing every single value to every single other value in the array.

i'm sure this can be implemented on a larger scale like i envisioned, but it is beyond my capabilities to pull that off.
chepfaust is offline   Reply With Quote
Old Jun 7th, 2006, 6:51 PM   #7
KTiger
Newbie
 
KTiger's Avatar
 
Join Date: May 2006
Location: Narvik, Norway
Posts: 22
Rep Power: 0 KTiger is on a distinguished road
As I see it u got 2 ways to solve this prb.
1. Use the high-precion-timer that follows with the OS, the multimedia timer.. to take the system clock( get next "tick"), which got alot of numbers something like 7836490734, and the next (tick) millisecond increments with 1, so you NEVER gonna get the number twice. If I remember it right it was a function called "GetNextTick()" in "mmci.dll".
2. I know there is a function in winapi that manages filenames for temporary filenames (I have NOT tested this).

Here is a tool the made my breakthrough, API-Guide .
This tools giving you way to look some simple examples for most of windows API's
(I did use this tool in the days of windows 98, so I hope M$ havent f*** it up in XP )
__________________
To sell your own books it's like selling a piece of your soul. Kim
KTiger is offline   Reply With Quote
Old Jun 7th, 2006, 8:49 PM   #8
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
Quote:
Originally Posted by KTiger
As I see it u got 2 ways to solve this prb.
1. Use the high-precion-timer that follows with the OS, the multimedia timer.. to take the system clock( get next "tick"), which got alot of numbers something like 7836490734, and the next (tick) millisecond increments with 1, so you NEVER gonna get the number twice. If I remember it right it was a function called "GetNextTick()" in "mmci.dll".
argh! that's exactly what i was trying to figure out days ago but nobody answered.

thanks
chepfaust is offline   Reply With Quote
Old Jun 8th, 2006, 5:04 AM   #9
KTiger
Newbie
 
KTiger's Avatar
 
Join Date: May 2006
Location: Narvik, Norway
Posts: 22
Rep Power: 0 KTiger is on a distinguished road
Oki here it is, this code DID work with Windows 98 and I haven't tested it with XP.

Put this in modul-section
Option Explicit

'Time Device
Public Declare Function GetTickCount& Lib "kernel32" ()
and put this in either form or module
Dim fTime As Long
fTime = GetTickCount&
And just repeat GetTickCount to get new tick, ie: 7893244643
basically it's number of ticks since 1970 1.january, and 1 tick = 1 millisecond

I hope this works for you, and remember this is VB6 code (not VB.net).
__________________
To sell your own books it's like selling a piece of your soul. Kim
KTiger is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:54 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC