Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Старожил


Сообщения: 352
Благодарности: 193

Профиль | Отправить PM | Цитировать


f0r_ce, Понятное дело, самое интересное - получить строку относительно её номера.
Например так

Код грязноват ибо не заботится о перезаписи переменных
Код: Выделить весь код
Name "RandomStringTest"
OutFile "RandomStringTest.exe"
ShowInstDetails show
AutoCloseWindow false
RequestExecutionLevel user
Page instfiles

Section ""
	StrCpy $0 string0
	StrCpy $1 string1
	StrCpy $2 string2
	StrCpy $3 string3
	
	DetailPrint "input 0 = $0"
	DetailPrint "input 1 = $1"
	DetailPrint "input 2 = $2"
	DetailPrint "input 3 = $3"
	
	Push $0
	Push $1
	Push $2
	Push $3

	Push 4 ; (число строк)
	nsRandom::GetRandom
	Pop $R0 ; random 0 <= N < 4)
	
	DetailPrint "random = $R0"
	
	StrCpy $R1 3
	
	loop:
	IntCmp $R1 0 0 exitloop 0
	IntCmp $R0 $R1 0 +2 +2
		Exch $5
	Pop $4
	IntOp $R1 $R1 - 1
	Goto loop
	exitloop:
	
	DetailPrint "result = $5"
	DetailPrint " "
	
SectionEnd


Более корректный вариант, оформлен как функция:
Скрытый текст

Код: Выделить весь код
Name "RandomStringTesFunc"
OutFile "RandomStringTesFunc.exe"
ShowInstDetails show
AutoCloseWindow false
RequestExecutionLevel user
Page instfiles

Section ""
	StrCpy $R0 0
	LoopS:
		Push string1
		Push string2
		Push string3
		Push string4
		Push string5
		Push 5
		Call GetRandomString
		Pop $0
		
		DetailPrint "result = $0"
		
		IntOp $R0 $R0 + 1
		InTCmp $R0 20 +2 0
		Goto LoopS
SectionEnd


Function GetRandomString
	Exch $0 ; stack size input for nsRandom::GetRandom
	Push $1 ; stack size, counts from zero
	Push $2 ; temp
	Push $3 ; output string
	
	IntOp $1 $0 - 1
	
	Push $0
	nsRandom::GetRandom
	Pop $0 ; get random (0 <= $0 <= $1)
	
	loop:
		IntCmp $1 0 0 exitloop 0
		Exch 4
		IntCmp $0 $1 0 +3 +3
			Pop $3
			Goto +2
		Pop $2
		Exch
		Exch 2
		Exch 3
		IntOp $1 $1 - 1
		Goto loop
	exitloop:
	
	Exch 3
	Pop $0
	Pop $2
	Pop $1
	Exch $3
FunctionEnd

Последний раз редактировалось iglezz, 30-09-2019 в 18:24.

Это сообщение посчитали полезным следующие участники:

Отправлено: 11:10, 30-09-2019 | #2318