![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2007
Posts: 19
Rep Power: 0
![]() |
RND batch file example
Hello, Could some one please help me out and post an example Randomize function in batch? One that produces random text or numbers like the RND lib function in VB.
Thanks in advance. cueballr. =] |
|
|
|
|
|
#2 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,004
Rep Power: 5
![]() |
Re: RND batch file example
Why not just write a small program, in whatever language, that generates random numbers and/or text, and then call it from the batch file? You also never said how you want the numbers/text. Are you wanting them to be displayed on the screen? This is quite simple. Do you want to use the output of the program as input into another program? This is also petty simple, as the program itself will be the same, but you will use pipes in the batch file. Do you want something else entirely? Your post was pretty vague, so you'll either need to give more information, or ask a psychic person for assistance.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Oct 2007
Posts: 19
Rep Power: 0
![]() |
Re: RND batch file example
If i would have wanted to call a VB RND program i would have done so, but i want an example in batch code, and no i dont want to use the out put as the input of another program, i simply want to use the function to name temp files, or anything else for that matter.Assistance would be apreciated.
thanks in advance. cueballr. =] |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: RND batch file example
Whether or not your particular shell/batch facility has a randomize feature depends on your system and any utilities that have been added. Generally, you will find you need to invoke another program (and use redirection, temp files, etc.), whether it was written by you or someone else.
The response you got was perfectly sensible. Perhaps you'd prefer Google?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Oct 2007
Posts: 19
Rep Power: 0
![]() |
Re: RND batch file example
I googled it before i made the first post and found an example, but it was not the type i needed, also it flashed an error while running the script, i just wanted another one.
![]() If someone could point out the error in that script it would be appreciated. @ECHO OFF FOR %%v IN (1 2 3 4 5 6 7 8 9) DO SET R%%v=%%v %1 %0 :: 1 %R1% 2 %R2% 3 %R3% 4 %R4% 5 %R5% 6 %R6% 7 %R7% 8 %R8% 9 %R9% ECHO. | TIME > RAND.DAT :Loop1 FIND ".%2" RAND.DAT >NUL IF ERRORLEVEL 1 FOR %%v IN (SET SHIFT GOTO:Loop1) DO %%v R%2=%3 DEL RAND.DAT SET RANDOM=%3 SET TANDOM=%7 ECHO %RANDOM%%TANDOM% >rresult.txt GOTO END :END the error flashed while running the above is "Invalid Parameter to SHIFT command" and FYI it does write the file "rresult.txt", but its the same data written into the file everytime, and if im not mistaken thats not what it should be doing. any help would be nice. =] thanks. cueballr. =] |
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: RND batch file example
This doesn't make any sense:
FOR %%v IN (SET SHIFT GOTO:Loop1) DO %%v R%2=%3That's going to try to generate some like: SET R1=1 SHIFT R1=1 GOTO:Loop1 R1=1
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Oct 2007
Posts: 19
Rep Power: 0
![]() |
Re: RND batch file example
Could you suggest a fix to that code?, is that possibly why it always writes "13" to the "rresult.txt" file?
![]() |
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Re: RND batch file example
It turns out that command extensions are on by default, so the SHIFT with a parameter will definitely fail.
Explain what you're trying to accomplish, and what parameters you will be passing and what they're for. Your original post asks for a random number and doesn't explain your goal. Your script seems to be wanting to use TIME for random generation. Given the output of TIME, it seems like a relatively poor choice for anything but the ugliest generation of a variable file name.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#9 | |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,004
Rep Power: 5
![]() |
Re: RND batch file example
Quote:
tmpnam() in C/C++.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Batch File - Running a exe and closing the winodw | mark84 | Bash / Shell Scripting | 2 | Dec 20th, 2006 12:22 AM |
| Windows batch file script | chronosoft | Other Scripting Languages | 6 | Oct 10th, 2006 9:43 AM |
| Embedding a batch file into a C++ app | vynkz | C++ | 22 | May 18th, 2005 8:59 PM |
| Batch file to expand and minimize start menu | Josef_Stalin | Other Programming Languages | 10 | May 11th, 2005 2:26 PM |
| Update registry key value via batch file | dpasswat | Other Scripting Languages | 1 | Mar 17th, 2005 10:45 AM |