| 1. |
Solve : Random number 40-90? |
|
Answer» I have been looking for a batch who random chose a number 40-90, but I can't find any command who can specify a certain number. Why I want 40-90 is because I USE 1-25 already and the 25-39 I made SPACE if I'm going to use more numbers later. have you created the labels :40 and :41 for it to jump to ? yes, I also have 40-90 Code: [Select]%rnd% ((<=If that number is 40 then)) GOTO 40 %rnd% ((<=If that number is 41 then)) GOTO 41 Is this really part of your "code", Frejoh466? If so, I believe I know why your script keeps crashing. Quote from: Frejoh466 on August 03, 2010, 01:51:22 PM I'm still learning how to use all batch commands, I just know the basics of it, but I would be grateful if anyone have the knowledge how can help me. since you have only just started, why not learn a programming language? A good programming language such as Python (and others) provides you programming concepts and constructs, such as arrays, hashes, dictionaries that every programmer should know and many more. Plus, it comes with modules/libraries that make programming easier and fun. Here's one way to get random number in Python. Code: [Select]import random random_number=random.randrange(100) if random_number < 40: print "do something" elif random_number<90: print "do something" Quote from: Salmon TROUT on August 04, 2010, 04:46:41 AM Code: [Select]%rnd% ((<=If that number is 40 then)) GOTO 40 That is not what my code look like, my code is kinda long so I only use the part that don't work so it wont be that long... I'm trying to use that code in this part, Code: [Select]if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto unlock if NOT EXIST Hide goto create :lock ren Hide "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto End :unlock echo Enter password to Unlock folder set /p "pass=>" if NOT %pass%==lol goto exit attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Hide goto exit :create md Hide goto exit :exit exit note quote marks Code: [Select]if NOT "%pass%"=="lol" goto exit Quote from: Salmon Trout on August 04, 2010, 05:22:48 AM note quote marks But it work without the quotes. Quote from: Frejoh466 on August 04, 2010, 06:40:44 AM But it work without the quotes. Try pressing ENTER when it asks for the password. Frejoh466, you changed scripts! First it was all that "goto 40" stuff, then all of a sudden you're trying to hide Control Panel! What's going on? What do you think this line is going to do? (Line 6) Code: [Select]goto End Quote from: Salmon Trout on August 04, 2010, 07:18:42 AM Frejoh466, you changed scripts! First it was all that "goto 40" stuff, then all of a sudden you're trying to hide Control Panel! What's going on? And this is why I only post the part that don't work... Ok forget my last post, I'm trying to use that random number the %rnd% create to go to the :40 or :41 etc. so the number that %rnd% create it will goto Hope this get through...Whatever it is you are trying to do, I am quite sure that there is a better way. Probably involving fewer lines! The computed goto is heavily frowned upon by programming experts. However if that is what you want... (You can change intHighNumber and put in the label sections from 51 to 90 yourself. Notice that you do not need goto end after the last number because you are going there anyway.) Code: [Select]echo off set intLowNumber=40 set intHighNumber=50 set /a rnd=%random% %% (%intHighNumber% - %intLowNumber% + 1) + %intLowNumber% goto %rnd% :40 echo number=40 goto end :41 echo number=41 goto end :42 echo number=42 goto end :43 echo number=43 goto end :44 echo number=44 goto end :45 echo number=45 goto end :46 echo number=46 goto end :47 echo number=47 goto end :48 echo number=48 goto end :49 echo number=49 goto end :50 echo number=50 :end |
|