[SOLVED] SET /a -- Random Number?
Moderator: DosItHelp
Re: [SOLVED] SET /a -- Random Number?
del
Last edited by taripo on 13 Dec 2011 15:30, edited 3 times in total.
Re: [SOLVED] SET /a -- Random Number?
'
hmm, do you really need command.COM
Try .CMD for batch extension...
hmm, do you really need command.COM
Try .CMD for batch extension...
Re: [SOLVED] SET /a -- Random Number?
del
Last edited by taripo on 13 Dec 2011 15:31, edited 1 time in total.
Re: [SOLVED] SET /a -- Random Number?
'
I get a decimal value 166 and 167 from 0xA6, and 0xA7, however ¦ is dec 221 = 0xDD
I get a decimal value 166 and 167 from 0xA6, and 0xA7, however ¦ is dec 221 = 0xDD
Re: [SOLVED] SET /a -- Random Number?
del
Last edited by taripo on 13 Dec 2011 15:31, edited 2 times in total.
Re: [SOLVED] SET /a -- Random Number?
It depends on your locale settings which codepages are used. You will find them in the registry.
That code returns for my German settings:
Means codepage 850 (ASCII) and codepage 1252 (ANSI).
If you save your code in ANSI it is however interpreted in ASCII in your command window. For that reason some characters are not displayed in the same manner.
E.g. Hex 0xA9 represents character © in codepage 1252 but character ® in codepage 850.
(ref. http://en.wikipedia.org/wiki/Code_page_850, http://en.wikipedia.org/wiki/Windows-1252)
BTW: That discussion is a bit off topic in a "SET /A" thread, isn't it
Regards
aGerman
Code: Select all
@echo off &setlocal
for /f "tokens=2*" %%i in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage" /v "OEMCP"') do set /a OEMCP=%%j
for /f "tokens=2*" %%i in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage" /v "ACP"') do set /a ACP=%%j
set OEMCP
set ACP
pause>nul
That code returns for my German settings:
Code: Select all
OEMCP=850
ACP=1252
Means codepage 850 (ASCII) and codepage 1252 (ANSI).
If you save your code in ANSI it is however interpreted in ASCII in your command window. For that reason some characters are not displayed in the same manner.
E.g. Hex 0xA9 represents character © in codepage 1252 but character ® in codepage 850.
(ref. http://en.wikipedia.org/wiki/Code_page_850, http://en.wikipedia.org/wiki/Windows-1252)
BTW: That discussion is a bit off topic in a "SET /A" thread, isn't it
Regards
aGerman
Re: [SOLVED] SET /a -- Random Number?
Note: agerman, you're welcome to delete your post since it's in the first of the 2 links here
a few issues about encodings
viewtopic.php?f=3&t=2647&p=12098#p12098
viewtopic.php?f=3&t=2550
a few issues about encodings
viewtopic.php?f=3&t=2647&p=12098#p12098
viewtopic.php?f=3&t=2550
Last edited by taripo on 13 Dec 2011 15:28, edited 2 times in total.
Re: [SOLVED] SET /a -- Random Number?
Ed, i'm just looking into your great macro idea.. and I see dave benham's great posts here and jeb's recent thing.. which i'll have to study some time.. and will include for reference here "Macros with parameters appended" viewtopic.php?f=3&t=2518
on a similar note to something in dave benham's post
since you can do the macro with one FOR statement, not two.. By skipping the first FOR
Do you actually prefer doing it with the FOR statement to set
Get.RandomNumber.TokenSTR
When you could use just use Set alone.
so that first For line could be replaced with that set line..
I suppose if you've used 2 FOR statements in other macros then this would apply to any of your macros.. Where you could use one FOR instead of 2. I see dave benham for example did it with one FOR.
Everything to the right of the first = in each for loop is identical.
on a similar note to something in dave benham's post
since you can do the macro with one FOR statement, not two.. By skipping the first FOR
Do you actually prefer doing it with the FOR statement to set
Get.RandomNumber.TokenSTR
When you could use just use Set alone.
so that first For line could be replaced with that set line..
I suppose if you've used 2 FOR statements in other macros then this would apply to any of your macros.. Where you could use one FOR instead of 2. I see dave benham for example did it with one FOR.
Everything to the right of the first = in each for loop is identical.
Code: Select all
:: for %%? in ( Get.RandomNumber.TokenSTR ) do set "%%~?=set /a Minimum = %%~b ^&set /a Maximum = %%~c ^&set /a interval = ^^^!Maximum^^^! - ^^^!Minimum^^^! ^&call set /a %%~d = %%Random%% ^&set /a %%~d = ^^^!%%~d^^^! * ^^^!interval^^^! / 32767 + ^^^!Minimum^^^! ^&( echo. ^&echo. ^&set /p "?= %%~d : '^^^!%%~d^^^!' [OK]" ^<nul ) "
set "Get.RandomNumber.TokenSTR=set /a Minimum = %%~b ^&set /a Maximum = %%~c ^&set /a interval = ^^^!Maximum^^^! - ^^^!Minimum^^^! ^&call set /a %%~d = %%Random%% ^&set /a %%~d = ^^^!%%~d^^^! * ^^^!interval^^^! / 32767 + ^^^!Minimum^^^! ^&( echo. ^&echo. ^&set /p "?= %%~d : '^^^!%%~d^^^!' [OK]" ^<nul ) "
Re: [SOLVED] SET /a -- Random Number?
'
This macro has evolved significantly. Unfortunately it is now interconnected and is useless without significantly rewriting it to use it outside it's library. This is a problem on a DOSTips forum
O that ?, ignore it, totally outdate...taripo wrote:Do you actually prefer doing it with the FOR statement to set
Get.RandomNumber.TokenSTR
This macro has evolved significantly. Unfortunately it is now interconnected and is useless without significantly rewriting it to use it outside it's library. This is a problem on a DOSTips forum
Code: Select all
% % set ^"%$defines%=!Jdelim_! ( %$n1c%
% % call set /a %%~a = %%Random%% %%%% %E7%( %%~c - %%~b + 1 %E7%) + %%~b ^|^|!@gErr! %$n1c%
% % ) else set $="
Code: Select all
>con ( %Random_% $var, 0, 999 ) &&echo.$var=!$var!_ ||echo.I see problem: '!$err!' ^!
Re: [SOLVED] SET /a -- Random Number?
Ed Dyreen wrote:'O that ?, ignore it, totally outdate...taripo wrote:Do you actually prefer doing it with the FOR statement to set
Get.RandomNumber.TokenSTR
This macro has evolved significantly. Unfortunately it is now interconnected and is useless without significantly rewriting it to use it outside it's library. This is a problem on a DOSTips forumCode: Select all
% % set ^"%$defines%=!Jdelim_! ( %$n1c%
% % call set /a %%~a = %%Random%% %%%% %E7%( %%~c - %%~b + 1 %E7%) + %%~b ^|^|!@gErr! %$n1c%
% % ) else set $="Code: Select all
>con ( %Random_% $var, 0, 999 ) &&echo.$var=!$var!_ ||echo.I see problem: '!$err!' ^!
looks interesting.. I like the fact that the old version is still there 'cos I still learn a bit about how the batch language works or can work, from playing with code like yours!