Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 02-23-2006, 07:42 PM   #1
In Runtime
 
outlawstar4761's Avatar
 
Join Date: Jan 2005
Posts: 186
Default Randomize in C++ Or VB

I know that in JavaScript there is an object that can give "random" results. Would it be possible to write a program in C++ or visual basic that will scan the contents of a folder and sub folders (or just a folder) and the program send me back a random file? Not neccessarly open it, just give the name.

Thanks.
__________________

outlawstar4761 is offline   Reply With Quote
Old 02-23-2006, 11:37 PM   #2
Daemon Poster
 
RewtGuy's Avatar
 
Join Date: Dec 2004
Posts: 595
Send a message via AIM to RewtGuy
Default Re: Randomize in C++ Or VB

Yeah It's possible.
__________________

__________________
Windows: A thirty-two bit extension and GUI shell to a sixteen bit patch to an eight bit operating system originally coded for a four bit microprocessor and sold by a two-bit company that can't stand one bit of competition.
RewtGuy is offline   Reply With Quote
Old 02-24-2006, 07:23 AM   #3
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,004
Default Re: Randomize in C++ Or VB

BV has a randomise function for generating random numbers within limits...

so yes...
find out how many file are in the folder..
generate a random number (e.g five) and return that file (e.g the five filename).
__________________
I didnít fight my way to the top of the food chain to be a vegetarianÖ
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 02-24-2006, 03:37 PM   #4
Daemon Poster
 
RewtGuy's Avatar
 
Join Date: Dec 2004
Posts: 595
Send a message via AIM to RewtGuy
Default Re: Randomize in C++ Or VB

I don't know what libaray / function can read file names from a directory in windows.

For Linux it's opendir readdir and closedir. if you don't know how to use it, man them. What I'd do is put the file names into an array. use a random number function (there's a lot out there) and you can adjust what you get by using the % operator. then assign the variable to the random number, then stick it in the array [x]; and get the x element.
__________________
Windows: A thirty-two bit extension and GUI shell to a sixteen bit patch to an eight bit operating system originally coded for a four bit microprocessor and sold by a two-bit company that can't stand one bit of competition.
RewtGuy is offline   Reply With Quote
Old 02-26-2006, 11:40 AM   #5
Fully Optimized
 
–88's Avatar
 
Join Date: May 2005
Posts: 4,775
Send a message via MSN to –88
Default Re: Randomize in C++ Or VB

Quote:
Originally Posted by RewtGuy
I don't know what libaray / function can read file names from a directory in windows.

For Linux it's opendir readdir and closedir. if you don't know how to use it, man them. What I'd do is put the file names into an array. use a random number function (there's a lot out there) and you can adjust what you get by using the % operator. then assign the variable to the random number, then stick it in the array [x]; and get the x element.
yeah in a case like that you can use the rand() or srand() functions to get the random effect.
__________________
Killing under the cloak of war is no different than murder

Kein Alkohol ist auch keine LŲsung!
–88 is offline   Reply With Quote
Old 04-03-2006, 09:51 AM   #6
Baseband Member
 
Join Date: Jul 2005
Posts: 55
Default Re: Randomize in C++ Or VB

For VB, I know there is the Rnd function, but this produces the same random sequence every time a program is executed. Is there any way, perhaps a different function, that would produce different sequences of random numbers every time a program is run? Thanks.
Argon is offline   Reply With Quote
Old 04-03-2006, 03:52 PM   #7
In Runtime
 
outlawstar4761's Avatar
 
Join Date: Jan 2005
Posts: 186
Default Re: Randomize in C++ Or VB

You can do it with JS.

That's what I used to write the program I was trying to make when I posted this thread
outlawstar4761 is offline   Reply With Quote
Old 04-04-2006, 05:27 AM   #8
Daemon Poster
 
RewtGuy's Avatar
 
Join Date: Dec 2004
Posts: 595
Send a message via AIM to RewtGuy
Default Re: Randomize in C++ Or VB

not as bad as some but this post was still a month old. hmm...
__________________
Windows: A thirty-two bit extension and GUI shell to a sixteen bit patch to an eight bit operating system originally coded for a four bit microprocessor and sold by a two-bit company that can't stand one bit of competition.
RewtGuy is offline   Reply With Quote
Old 04-09-2006, 08:27 AM   #9
j03
~~~~~~~~
 
Join Date: Jan 2005
Location: Wales
Posts: 5,556
Send a message via MSN to j03
Default Re: Randomize in C++ Or VB

About two months a made a Cheesy program: "Rannum - For all your random need's" That made random Numbers... Cant rember how... (It was in VB)
__________________

j03 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 10:40 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0