Solved ima noob at FOR /F loop ... gota problem

September 26, 2012 at 18:27:14
Specs: Windows 7
Alright so what i got here is this: I have rand1 randomly generating a number between 1 and 4. If the number equals 1 it uses the 5 letter word list for the variable Ewords. If it yields 2 then its 6 letter word list and if its 3 its a 7 letter word list, and finally if rand1 is equal to 4 it will set Ewords equal to the list of 8 letter words. After I got that done, I want to select a random word from the variable Ewords and set it to be equal to a variable called password. Obviously this is generating a password. The variable tokenc is the amount of tokens in variable Ewords. because i have a different number of words for each list, I needed the number of tokens when I was generating the random password from Ewords. So far, I tested this and it's working decently, but it's not picking a random word for the password. I know for sure its a problem in my FOR loops down at the bottom... I do this to test : Echo %Ewords% %rand1% %pass% %tokenc% %rand2% so i can see all the results. the one thats problematic is %pass% which is for some reason always and i mean always equal to the very first word in the world list Ewords. I need it to pick a random word from the Ewords list, maybe someone can help me?

set /a rand1=%random% %% 4+1
IF /I %rand1%==1 set Ewords=AZURE BEIGE BLACK BROWN FLESH GREEN MAIZE OCHRE OLIVE SEPIA SLATE STEEL WHITE BACON CANDY GRAPE GRAVY GRITS JUICE OMLET PEACH PIZZA SALAD STEAK BISON BUNNY CAMEL HORSE HYENA KOALA LLAMA PANDA SHARK TIGER WHALE CHILE CHINA EGYPT GHANA HAITI INDIA ITALY JAPAN KENYA NEPAL SPAIN TIBET BLAST BLEND COUNT DANCE LEARN LEAVE MARCH SLEEP SLIDE SMELL SMILE TEASE THINK TWIRL WEAVE BRICK FIBER GLASS IVORY LINEN MULCH NYLON PAINT PAPER SLATE STEEL STRAW WATER & set charc=5 & set tokenc=75
IF /I %rand1%==2 set Ewords=BRONZE CANARY COPPER FOREST INDIGO MAROON ORANGE SALMON SHADOW SILVER VIOLET YELLOW CARROT CHEESE CHERRY COFFEE COOKIE HOTDOG MUFFIN ORANGE POTATO RADISH SHRIMP TOMATO TURKEY WAFFLE BADGER BABOON BEAVER CANARY COUGAR COYOTE DONKEY FERRET GOPHER IGUANA JACKAL KITTEN LIZARD MONKEY PARROT RABBIT TURTLE WALRUS WEASEL BRAZIL CANADA FRANCE GREECE ISRAEL LATVIA MEXICO MONACO NORWAY POLAND RUSSIA SWEDEN TURKEY BATTLE BOUNCE CHOOSE CUDDLE GATHER LISTEN PONDER SHOWER TYPING WONDER ANGORA BAMBOO BRONZE CARBON CEMENT COPPER COTTON FLEECE MARBLE RUBBER SILVER & set charc=6 & set tokenc=79
IF /I %rand1%==3 set Ewords=CRIMSON MAGENTA SCARLET BISCUIT BURRITO CHICKEN CHOWDER CUPCAKE KETCHUP LETTUCE LOBSTER MUSTARD PANCAKE POPCORN SAUSAGE BUFFALO GAZELLE GIRAFFE GORILLA HAMSTER LEOPARD OPOSSUM RACCOON AMERICA AUSTRIA BELGUIM DENMARK ECUADOR ENGLAND ESTONIA FINLAND GERMANY HUNGARY ICELAND IRELAND JAMACIA VIETNAM BALANCE DELIVER FLUTTER GLIMMER HOPPING LOOKING OBSERVE PRETEND RUNNING SHIMMER STRETCH TWINKLE ASPHALT FLANNEL PLASTER PLASTIC SPANDEX & set charc=7 & set tokenc=54
IF /I %rand1%==4 set Ewords=BURGUNDY CERULEAN CHARCOAL MAHOGANY SHAMROCK CUCUMBER LOLLYPOP BROCCOLI MUSHROOM PORKCHOP SANDWICH TORTILLA AARDVARK ANTEATER CHIPMUNK ELEPHANT HEDGEHOG KANGAROO MONGOOSE PARAKEET SQUIRREL BULGARIA CAMBODIA MONGOLIA PORTUGAL SCOTLAND BUILDING CHOOSING EXERCISE FEASTING LAUGHING POINTING PRACTICE SPINNING SPRINKLE SWIMMING CASHMERE CONCRETE FILAMENT BACKWASH DAMPNESS EJECTION GATHERED HACKSAWS RICKROLL JALAPENO KILOWATT PACKAGES SABOTAGE VAGRANCY & set charc=8 & set tokenc=50
FOR /F "tokens=*" %%G IN ('%Ewords%') DO set /a %%G=%random% %% %tokenc%+1
FOR /F %%G IN ('set /a %%G=%random% %% %tokenc%+1') set %pass%=token %%G
ECHO password is %pass%


See More: ima noob at FOR /F loop ... gota problem

Report •


✔ Best Answer
September 27, 2012 at 20:01:48
Family and work sounds better than football, so let's go with that.

Not my best work, but this is one of two ways to get around a bug in FOR /F's token parsing. The other option is to call a function and call SHIFT from a loop, which would be the only sane solution if these words weren't fixed length.

set Ewords5=AZURE BEIGE BLACK BROWN FLESH GREEN MAIZE ^
OCHRE OLIVE SEPIA SLATE STEEL WHITE BACON CANDY GRAPE GRAVY GRITS JUICE ^
OMLET PEACH PIZZA SALAD STEAK BISON BUNNY CAMEL HORSE HYENA KOALA LLAMA ^
PANDA SHARK TIGER WHALE CHILE CHINA EGYPT GHANA HAITI INDIA ITALY JAPAN ^
KENYA NEPAL SPAIN TIBET BLAST BLEND COUNT DANCE LEARN LEAVE MARCH SLEEP ^
SLIDE SMELL SMILE TEASE THINK TWIRL WEAVE BRICK FIBER GLASS IVORY LINEN ^
MULCH NYLON PAINT PAPER SLATE STEEL STRAW WATER & set tokenc5=75

SET Ewords6=BRONZE CANARY COPPER FOREST INDIGO MAROON ^
ORANGE SALMON SHADOW SILVER VIOLET YELLOW CARROT CHEESE CHERRY COFFEE ^
COOKIE HOTDOG MUFFIN ORANGE POTATO RADISH SHRIMP TOMATO TURKEY WAFFLE ^
BADGER BABOON BEAVER CANARY COUGAR COYOTE DONKEY FERRET GOPHER IGUANA ^
JACKAL KITTEN LIZARD MONKEY PARROT RABBIT TURTLE WALRUS WEASEL BRAZIL ^
CANADA FRANCE GREECE ISRAEL LATVIA MEXICO MONACO NORWAY POLAND RUSSIA ^
SWEDEN TURKEY BATTLE BOUNCE CHOOSE CUDDLE GATHER LISTEN PONDER SHOWER ^
TYPING WONDER ANGORA BAMBOO BRONZE CARBON CEMENT COPPER COTTON FLEECE ^
MARBLE RUBBER SILVER & set tokenc6=79

SET Ewords7=CRIMSON MAGENTA SCARLET BISCUIT BURRITO ^
CHICKEN CHOWDER CUPCAKE KETCHUP LETTUCE LOBSTER MUSTARD PANCAKE POPCORN ^
SAUSAGE BUFFALO GAZELLE GIRAFFE GORILLA HAMSTER LEOPARD OPOSSUM RACCOON ^
AMERICA AUSTRIA BELGUIM DENMARK ECUADOR ENGLAND ESTONIA FINLAND GERMANY ^
HUNGARY ICELAND IRELAND JAMACIA VIETNAM BALANCE DELIVER FLUTTER GLIMMER ^
HOPPING LOOKING OBSERVE PRETEND RUNNING SHIMMER STRETCH TWINKLE ASPHALT ^
FLANNEL PLASTER PLASTIC SPANDEX & set tokenc7=54

SET Ewords8=BURGUNDY CERULEAN CHARCOAL MAHOGANY SHAMROCK ^
CUCUMBER LOLLYPOP BROCCOLI MUSHROOM PORKCHOP SANDWICH TORTILLA AARDVARK ^
ANTEATER CHIPMUNK ELEPHANT HEDGEHOG KANGAROO MONGOOSE PARAKEET SQUIRREL ^
BULGARIA CAMBODIA MONGOLIA PORTUGAL SCOTLAND BUILDING CHOOSING EXERCISE ^
FEASTING LAUGHING POINTING PRACTICE SPINNING SPRINKLE SWIMMING CASHMERE ^
CONCRETE FILAMENT BACKWASH DAMPNESS EJECTION GATHERED HACKSAWS RICKROLL ^
JALAPENO KILOWATT PACKAGES SABOTAGE VAGRANCY & set tokenc8=50

SET /A charc = %random% %% 4 + 5
SET /A wordNum = %random% %% tokenc%charc%
SET /A offset = wordNum * (charc + 1)
SET pass=%%Ewords%charc%:~%offset%,%charc%%%
CALL SET pass=%pass%
@ECHO %charc%: %wordNum% =^> %pass%
Now back to football.

How To Ask Questions The Smart Way



#1
September 26, 2012 at 23:32:30
Please help us to help you by posting your scripts in an easy-to-read format always using the Pre function to preserve layout.. I suggest the following format:

set /a rand1=%random% %% 4+1

IF /I %rand1%==1 set Ewords=AZURE BEIGE BLACK BROWN FLESH GREEN MAIZE ^
OCHRE OLIVE SEPIA SLATE STEEL WHITE BACON CANDY GRAPE GRAVY GRITS JUICE ^
OMLET PEACH PIZZA SALAD STEAK BISON BUNNY CAMEL HORSE HYENA KOALA LLAMA ^
PANDA SHARK TIGER WHALE CHILE CHINA EGYPT GHANA HAITI INDIA ITALY JAPAN ^
KENYA NEPAL SPAIN TIBET BLAST BLEND COUNT DANCE LEARN LEAVE MARCH SLEEP ^
SLIDE SMELL SMILE TEASE THINK TWIRL WEAVE BRICK FIBER GLASS IVORY LINEN ^
MULCH NYLON PAINT PAPER SLATE STEEL STRAW WATER & set charc=5 & set tokenc=75

IF /I %rand1%==2 set Ewords=BRONZE CANARY COPPER FOREST INDIGO MAROON ^
ORANGE SALMON SHADOW SILVER VIOLET YELLOW CARROT CHEESE CHERRY COFFEE ^
COOKIE HOTDOG MUFFIN ORANGE POTATO RADISH SHRIMP TOMATO TURKEY WAFFLE ^
BADGER BABOON BEAVER CANARY COUGAR COYOTE DONKEY FERRET GOPHER IGUANA ^
JACKAL KITTEN LIZARD MONKEY PARROT RABBIT TURTLE WALRUS WEASEL BRAZIL ^
CANADA FRANCE GREECE ISRAEL LATVIA MEXICO MONACO NORWAY POLAND RUSSIA ^
SWEDEN TURKEY BATTLE BOUNCE CHOOSE CUDDLE GATHER LISTEN PONDER SHOWER ^
TYPING WONDER ANGORA BAMBOO BRONZE CARBON CEMENT COPPER COTTON FLEECE ^
MARBLE RUBBER SILVER & set charc=6 & set tokenc=79

IF /I %rand1%==3 set Ewords=CRIMSON MAGENTA SCARLET BISCUIT BURRITO ^
CHICKEN CHOWDER CUPCAKE KETCHUP LETTUCE LOBSTER MUSTARD PANCAKE POPCORN ^
SAUSAGE BUFFALO GAZELLE GIRAFFE GORILLA HAMSTER LEOPARD OPOSSUM RACCOON ^
AMERICA AUSTRIA BELGUIM DENMARK ECUADOR ENGLAND ESTONIA FINLAND GERMANY ^
HUNGARY ICELAND IRELAND JAMACIA VIETNAM BALANCE DELIVER FLUTTER GLIMMER ^
HOPPING LOOKING OBSERVE PRETEND RUNNING SHIMMER STRETCH TWINKLE ASPHALT ^
FLANNEL PLASTER PLASTIC SPANDEX & set charc=7 & set tokenc=54

IF /I %rand1%==4 set Ewords=BURGUNDY CERULEAN CHARCOAL MAHOGANY SHAMROCK ^
CUCUMBER LOLLYPOP BROCCOLI MUSHROOM PORKCHOP SANDWICH TORTILLA AARDVARK ^
ANTEATER CHIPMUNK ELEPHANT HEDGEHOG KANGAROO MONGOOSE PARAKEET SQUIRREL ^
BULGARIA CAMBODIA MONGOLIA PORTUGAL SCOTLAND BUILDING CHOOSING EXERCISE ^
FEASTING LAUGHING POINTING PRACTICE SPINNING SPRINKLE SWIMMING CASHMERE ^
CONCRETE FILAMENT BACKWASH DAMPNESS EJECTION GATHERED HACKSAWS RICKROLL ^
JALAPENO KILOWATT PACKAGES SABOTAGE VAGRANCY & set charc=8 & set tokenc=50

What you are trying to do with the For loops after this is a mystery to me but you cannot use a single quotation mark to indicate a string so ...in ('%Ewords%')... is incorrect as is the lack of DO in one of the for loops.


Please come back & tell us if your problem is resolved.


Report •

#2
September 27, 2012 at 04:40:17
wow that does look a lot better. thanks!
as for the for loops I am trying to make it select a random word from the Variable Ewords. Ewords is a list of possible passwords. Whatever random word it picks i need it to set equal to the %pass% variable. istill cant get this loop to work

BTW tokenc is a variable that is the number of words in the list of Ewords. i made that variable so that in the random i could do rand=%random% tokenc+1

and finally, after it has the password i need it to compare the user input to the password and echo the amount of characters you got right out of total characters. So if you entered Beige and the password is black it would echo: echo you got 1/5 characters right

I could really use help her? please?


Report •

#3
September 27, 2012 at 15:36:37
can i please get an answer?? i cant continue with this program until i get past this roadblock. i only got a week left for this

Report •

Related Solutions

#4
September 27, 2012 at 16:42:31
Well, I know I'm not interested until I see proper Shift key usage. Good grammar and spelling, too.

EDIT: It's called artistic license.

How To Ask Questions The Smart Way


Report •

#5
September 27, 2012 at 16:54:26
May I please get an answer? I can't continue on with my program until I can get this part right. Is that better?

Report •

#6
September 27, 2012 at 17:34:12
Razor your grammar isn't perfect either. One of the sentences you wrote was "Good grammar and spelling, too.", which is so incomplete I'm surprised you even bothered to tell me how bad MY grammar is.

Report •

#7
September 27, 2012 at 19:16:24
Hey, don't insult Razor, he's one of the best batch scripters on this forum. If you can get him interested in your problem he'll amaze you with his prompt responses.

Don't forget we have commitments to family, earning a living and sleeping too. My employer has had the temerity to ask me to sort out a bsod on one of the lan units rather than devoting time, for which she is paying me, to Computing.net. I'll be back with you later but cannot say when.


Please come back & tell us if your problem is resolved.


Report •

#8
September 27, 2012 at 19:48:11
sorry guys for being annoying. I reposted the question in a much much more clear manor with propper grammar and I read Razors article on how to properly ask questions. Thanks for your time.

Report •

#9
September 27, 2012 at 20:01:48
✔ Best Answer
Family and work sounds better than football, so let's go with that.

Not my best work, but this is one of two ways to get around a bug in FOR /F's token parsing. The other option is to call a function and call SHIFT from a loop, which would be the only sane solution if these words weren't fixed length.

set Ewords5=AZURE BEIGE BLACK BROWN FLESH GREEN MAIZE ^
OCHRE OLIVE SEPIA SLATE STEEL WHITE BACON CANDY GRAPE GRAVY GRITS JUICE ^
OMLET PEACH PIZZA SALAD STEAK BISON BUNNY CAMEL HORSE HYENA KOALA LLAMA ^
PANDA SHARK TIGER WHALE CHILE CHINA EGYPT GHANA HAITI INDIA ITALY JAPAN ^
KENYA NEPAL SPAIN TIBET BLAST BLEND COUNT DANCE LEARN LEAVE MARCH SLEEP ^
SLIDE SMELL SMILE TEASE THINK TWIRL WEAVE BRICK FIBER GLASS IVORY LINEN ^
MULCH NYLON PAINT PAPER SLATE STEEL STRAW WATER & set tokenc5=75

SET Ewords6=BRONZE CANARY COPPER FOREST INDIGO MAROON ^
ORANGE SALMON SHADOW SILVER VIOLET YELLOW CARROT CHEESE CHERRY COFFEE ^
COOKIE HOTDOG MUFFIN ORANGE POTATO RADISH SHRIMP TOMATO TURKEY WAFFLE ^
BADGER BABOON BEAVER CANARY COUGAR COYOTE DONKEY FERRET GOPHER IGUANA ^
JACKAL KITTEN LIZARD MONKEY PARROT RABBIT TURTLE WALRUS WEASEL BRAZIL ^
CANADA FRANCE GREECE ISRAEL LATVIA MEXICO MONACO NORWAY POLAND RUSSIA ^
SWEDEN TURKEY BATTLE BOUNCE CHOOSE CUDDLE GATHER LISTEN PONDER SHOWER ^
TYPING WONDER ANGORA BAMBOO BRONZE CARBON CEMENT COPPER COTTON FLEECE ^
MARBLE RUBBER SILVER & set tokenc6=79

SET Ewords7=CRIMSON MAGENTA SCARLET BISCUIT BURRITO ^
CHICKEN CHOWDER CUPCAKE KETCHUP LETTUCE LOBSTER MUSTARD PANCAKE POPCORN ^
SAUSAGE BUFFALO GAZELLE GIRAFFE GORILLA HAMSTER LEOPARD OPOSSUM RACCOON ^
AMERICA AUSTRIA BELGUIM DENMARK ECUADOR ENGLAND ESTONIA FINLAND GERMANY ^
HUNGARY ICELAND IRELAND JAMACIA VIETNAM BALANCE DELIVER FLUTTER GLIMMER ^
HOPPING LOOKING OBSERVE PRETEND RUNNING SHIMMER STRETCH TWINKLE ASPHALT ^
FLANNEL PLASTER PLASTIC SPANDEX & set tokenc7=54

SET Ewords8=BURGUNDY CERULEAN CHARCOAL MAHOGANY SHAMROCK ^
CUCUMBER LOLLYPOP BROCCOLI MUSHROOM PORKCHOP SANDWICH TORTILLA AARDVARK ^
ANTEATER CHIPMUNK ELEPHANT HEDGEHOG KANGAROO MONGOOSE PARAKEET SQUIRREL ^
BULGARIA CAMBODIA MONGOLIA PORTUGAL SCOTLAND BUILDING CHOOSING EXERCISE ^
FEASTING LAUGHING POINTING PRACTICE SPINNING SPRINKLE SWIMMING CASHMERE ^
CONCRETE FILAMENT BACKWASH DAMPNESS EJECTION GATHERED HACKSAWS RICKROLL ^
JALAPENO KILOWATT PACKAGES SABOTAGE VAGRANCY & set tokenc8=50

SET /A charc = %random% %% 4 + 5
SET /A wordNum = %random% %% tokenc%charc%
SET /A offset = wordNum * (charc + 1)
SET pass=%%Ewords%charc%:~%offset%,%charc%%%
CALL SET pass=%pass%
@ECHO %charc%: %wordNum% =^> %pass%
Now back to football.

How To Ask Questions The Smart Way


Report •

#10
September 27, 2012 at 20:12:42
Thank you so much Razor!! This is great and exactly what I was looking for. You have been very helpful.

I ran it and it worked right away :D


Report •

#11
September 27, 2012 at 20:40:27
Nice one Razor, always a pleasure to learn from your work.


Please come back & tell us if your problem is resolved.


Report •


Ask Question