Randomize in C++ Or VB

outlawstar4761

In Runtime
Messages
186
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.
 
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 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.
 
RewtGuy said:
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.
 
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.
 
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
 
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)
 
Back
Top Bottom