# random function

## Recommended Posts

hi all

i have this script and i want to make it when it's pole number to run Pole() when it's nonpole number to run nonpole()

for $x = 0 to 100$numb = Random(1,100,1)
Next

func Pole()
MsgBox(0, "result", "Pole")
EndFunc

func nonpole()
MsgBox(0, "result", "nonpole")
EndFunc

Next

some clue pls???

tnx

Edited by Kyme

##### Share on other sites

How are you defining what a pole number is?

You could do this for example:

for $x = 0 to 100$numb = Random(1,100,1)
Next

if $numb <= 50 then Pole() if$numb => 51 then noPole()

func Pole()
MsgBox(0, "result", "Pole")
EndFunc

func nonpole()
MsgBox(0, "result", "nonpole")
EndFunc

Next

##### Share on other sites

How are you defining what a pole number is?

You could do this for example:

for $x = 0 to 100$numb = Random(1,100,1)
Next

if $numb <= 50 then Pole() if$numb => 51 then noPole()

func Pole()
MsgBox(0, "result", "Pole")
EndFunc

func nopole()
MsgBox(0, "result", "nonpole")
EndFunc

Next
first think it's tnx @Volly for feedback

when i run the script multiple times and i got nr 1 to 50 it's pole and when i got 51 to 100 it's nonpole

i don't know if pole it's the corect word for this kind of number but i give ex

pole numbers=2,4,6,8,10 etc

nonpole number=1,3,5,7,9 etc

maybe i have says something wrong...my english it poor:|sry

can someone help me with this and if you can to make some like this it's awesome

when $numb=12 then 1+2=3, 3 it's nonpole number, to get msgbox(0,"result","sum= nonpole" when$numb=13 then 1+3=4, 4 it's pole number,to get msgbox(0,"result","sum= pole"

For $x = 0 to 100$numb = Random(1,100,1)
Next

If $numb <= 50 Then MsgBox(0, "result", "Pole " &$numb)
If $numb >= 51 Then MsgBox(0, "result", "nonpole" &$numb)

when i try

If $numb <= 50 Then MsgBox(0, "result", "Pole " &$numb)
If $numb => 51 Then MsgBox(0, "result", "nonpole" &$numb)

i got this err

: ==> Error in expression.:
If $numb => 51 then MsgBox(0, "result", "nonpole" &$numb)
If ^ ERROR

i please you all to help me with this

remain grateful

kyme

Edited by Kyme

##### Share on other sites

a even number is 2, 4, 6, 8, and so forth

a odd number is 1, 3, 5, 7, and so forth

Try this. I know StringRegExp would be a better way to go than what I did, but what I did does work.

dim $numb for$x = 0 to 100
$numb = Random(1,100,1) Next$numb1 = StringRight($numb, 1) if$numb1 = 2 or $numb1 =4 or$numb1 =6 or $numb1 =8 or$numb1 =0 then Pole()
if $numb1 = 1 or$numb1 =3 or $numb1 =5 or$numb1 =7 or $numb1 =9 then noPole() func Pole() MsgBox(0,$numb, "Even number")
EndFunc

func nopole()
MsgBox(0, $numb, "Odd number") EndFunc #### Share this post ##### Link to post ##### Share on other sites Hey, here you go For$x = 0 To 100
$numb = Random(1, 100, 1) If Mod($numb, 2) Then
Odd($numb) Else Even($numb)
EndIf
Next

Func Odd($numb) ConsoleWrite("Odd: " &$numb & @CRLF)
EndFunc   ;==>Odd

Func Even($numb) ConsoleWrite("Even: " &$numb & @CRLF)
EndFunc   ;==>Even

Edit: had odds and even switched

Edited by Robjong

##### Share on other sites

first think it's tnx @Volly for feedback

when i run the script multiple times and i got nr 1 to 50 it's pole and when i got 51 to 100 it's nonpole

i don't know if pole it's the corect word for this kind of number but i give ex

pole numbers=2,4,6,8,10 etc

nonpole number=1,3,5,7,9 etc

maybe i have says something wrong...my english it poor:|sry

can someone help me with this and if you can to make some like this it's awesome

when $numb=12 then 1+2=3, 3 it's nonpole number, to get msgbox(0,"result","sum= nonpole" when$numb=13 then 1+3=4, 4 it's pole number,to get msgbox(0,"result","sum= pole"

For $x = 0 to 100$numb = Random(1,100,1)
Next

If $numb <= 50 Then MsgBox(0, "result", "Pole " &$numb)
If $numb >= 51 Then MsgBox(0, "result", "nonpole" &$numb)

when i try

If $numb <= 50 Then MsgBox(0, "result", "Pole " &$numb)
If $numb => 51 Then MsgBox(0, "result", "nonpole" &$numb)

i got this err

: ==> Error in expression.:
If $numb => 51 then MsgBox(0, "result", "nonpole" &$numb)
If ^ ERROR

i please you all to help me with this

remain grateful

kyme

Here is a function to return the sum of the digits in a number.

Func Pole($numb) Local$d = Int($numb/10) if$d = 0 then return $numb return$numb - $d*10 + Pole($d)
EndFunc

If you only want a single digit, say because the sum is greater than 10, then

Func Apole($anum) Do$anum = Pole($anum) Until$anum < 10
return $anum endfunc Edited by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. #### Share this post ##### Link to post ##### Share on other sites @Volly Based upon part of his second post, 12 would be a non-pole number. This leads me to believe that he's not just wanting odd and even. I would also like to point out you are calculating 100 different random numbers and then doing something with the very last one, and then you are only checking the last digit in the column. However were he to want just strictly odd and even, and want to do it 100 times, then the below may be a better solution... Local$i_Number, $x For$x = 0 To 100 Step 1
$i_Number = Random(1, 100, 1) If Mod($i_Number, 2) = 0 Then
_PoleNumber() ;Even
Else
_NonPoleNumber() ;Odd
EndIf
Next
Granted I didn't create any functions for _PoleNumber() or _NonPoleNumber(), but you get the idea. (I hope)

@Kyme

Could you point to a Wikipedia article on the subject of Pole numbers? It seems your definition goes beyond just odd and even numbers.

Thanks,

Jarvis

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

##### Share on other sites

awsome tnx very very mush guys

i am grateful to all

tnx again

Regards, kyme

##### Share on other sites

i have one more think

i have try to make this some weeks ago and no result

how i can do this one

if i have one number created by 2 or more numbers then to sum all numbers

for exaple if i have

$number=111$sumnumber=3

operation 111=1+1+1 or

$number=241$sumnumber=7

operation 241=2+4+1 (each number from $number to be summed between it) to divide the number in each character and to sum it are this posible like this but with 3 character number between 100 and 999 $num1=42
$nr1 = StringTrimRight($num1, 1)
$nr2 = StringTrimLeft($num1, 1)
$sum=$nr1 + $nr2 MsgBox(0,$num1,$sum) i find this one...but other way...more safe exist? $num1=567
$help1 = StringTrimLeft($num1, 1)
$nr1 = StringTrimRight($num1, 2)
$nr2 = StringTrimRight($help1, 1)
$nr3 = StringTrimLeft($num1, 2)

$sum=$nr1 + $nr2 +$nr3
MsgBox(0,$num1,$nr1&"+"&$nr2&"+"&$nr3&"="&$sum) Edited by Kyme #### Share this post ##### Link to post ##### Share on other sites Kyme, You can use the following function that I have created. It may need to be tweaked as I haven't actually tested it, but it should work mostly without a hitch. Also, you may need to add your own error checking in there as I haven't checked for any at all. Func _SumNumberString($i_StartNumber)
Local $i_SumNumber,$i
Local $a_IndividualNumbers$a_IndividualNumbers = StringSplit($i_StartNumber, "")$i_SumNumber = 0 ; Clear the number so we can start fresh with the newly created number, not needed when in a function, but just being sure.

For $i = 1 To$a_IndividualNumbers[0] Step 1
$i_SumNumber +=$a_IndividualNumbers[$i] Next Return$i_SumNumber
EndFunc

I hope this helps in your AutoIt journeys.

Thanks,

Jarvis

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

##### Share on other sites

Kyme,

You can use the following function that I have created. It may need to be tweaked as I haven't actually tested it, but it should work mostly without a hitch. Also, you may need to add your own error checking in there as I haven't checked for any at all.

Func _SumNumberString($i_StartNumber) Local$i_SumNumber, $i Local$a_IndividualNumbers

$a_IndividualNumbers = StringSplit($i_StartNumber, "")

$i_SumNumber = 0 ; Clear the number so we can start fresh with the newly created number, not needed when in a function, but just being sure. For$i = 1 To $a_IndividualNumbers[0] Step 1$i_SumNumber += $a_IndividualNumbers[$i]
Next

Return \$i_SumNumber
EndFunc

I hope this helps in your AutoIt journeys.

Thanks,

Jarvis

wow...this is nice one...i use your function 2x in same time i have 2 function on pole nr and 2 function on unpole...

u have made really awesome func...tnx bro

Only good to all

Regards, kyme

## Create an account

Register a new account