Computer Forums

Computer Forums (http://www.computerforums.org/forums/)
-   Programming (http://www.computerforums.org/forums/programming/)
-   -   Randomize in C++ Or VB (http://www.computerforums.org/forums/programming/randomize-c-vbulletin-139221.html)

outlawstar4761 02-23-2006 06:42 PM

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.

RewtGuy 02-23-2006 10:37 PM

Re: Randomize in C++ Or VB
 
Yeah It's possible.

root 02-24-2006 06:23 AM

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).

RewtGuy 02-24-2006 02:37 PM

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.

88 02-26-2006 10:40 AM

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.

Argon 04-03-2006 08:51 AM

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.

outlawstar4761 04-03-2006 02:52 PM

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

RewtGuy 04-04-2006 04:27 AM

Re: Randomize in C++ Or VB
 
not as bad as some but this post was still a month old. hmm...

j03 04-09-2006 07:27 AM

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)


All times are GMT -5. The time now is 01:25 PM.

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