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.
 

root

Site Team
Staff member
Messages
8,181
Location
UK
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).
 

Cx

Daemon Poster
Messages
602
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

Fully Optimized
Messages
4,775
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.
 

Argon

Baseband Member
Messages
55
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.
 

j031

~~~~~~~~
Messages
5,556
Location
Wales
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)
 
Top