Sign in to follow this  
Followers 0
IKilledBambi

randomization

23 posts in this topic

This is almost what I want but, I want it to keep randomizing, after it randomizes one, it doesnt re-randomize.

$1 = Random( 1, 999, 1 )
While 1
    Sleep( 100 )
    Send($1)
WEnd

Share this post


Link to post
Share on other sites



Just move the random part to the line above the sleep part.

:)


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Cool thanks man, is there a way so that, if the number is 234 the program will close?

Share this post


Link to post
Share on other sites

If $1=234 Then Exit


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

ok then after that, how do i make it execute a function? I tried execute but it was fail xD

While 1
    $1 = Random( 1, 999, 1 )
    Sleep( 100 )
    Send( "{space}" )
    Send($1)
    if $1=666 then
        MsgBox(1, "AHHH DEVIL", "DEVIL AHHHHHHHHHHHHH" )
        Execute( devilish )
    EndIf
WEnd

Func devilish()
While 1
    Sleep( 100 )
WEnd
EndFunc

Share this post


Link to post
Share on other sites

You do not call functions with the Execute function, you do it simply like this:

devilish()


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Is there a way to recycle old numbers meaning, if 99 was said, it wont be said again?

Share this post


Link to post
Share on other sites

test this:

While 1
    $last = $1
    $1 = Random(1, 999, 1)
    While $1 = $last
        $1 = Random(1, 999, 1)
    WEnd
    ;rest of script goes here
WEnd

[center]It's a question of mind over matter, if I don't mind, it doesn't matter.[/center]

Share this post


Link to post
Share on other sites

no go

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Something like:

$MIN=1
$MAX=40
$string="|"

While 1
    Sleep(10)
    Do
        $temp=Random($MIN,$MAX,1)
    Until Not StringInStr($string,"|"&$temp&"|")
    Send($temp)
    $string&=$temp&"|"
    $array=StringRegExp($string,"\|",3)
    If Ubound($array)>=($MAX-$MIN+2) Then ExitLoop
WEnd

Could also be done with arrays...

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Hi, monoceres!

What if I have many text strings, and I want to randomly pick up one of them, and do not reapeat any previous one, but after they are all finished, start over, randomizing strings, and so on ? :)

Regards,

Kiti

Share this post


Link to post
Share on other sites

I thought of this the other day, it's basically a shuffle algorithm, like what you would use to place every card in a deck in a random position, without repeating the cards.

Easiest solution I could think of, was to make 2 arrays, both the size of the data. Fill 1 with your data to be shuffled.

Then, select one at random (using AutoIt's Random(1, 52, 1) for a standard card deck), add that card to the other array at position 1.

After the card is selected, remove it from the first array, and update a variable pointing at the current position in the 2nd array.

Next run, the Random function would run, but for one less (Random(1, 51, 1)), and so on, until you only had one card, and then you'd have it shuffled.

Only problem with that solution, would be the deleting elements from an array, that causes things to slow down a lot. For those willing to try, you could actually use just 1 array, and when you pick a card to be moved, just exchange it with either ending variable (just swap values), and change your Random function to match (either update the 1 to 2 if you add things at the beginning, or 52 to 51 if you add things to the end). That gives you a nice speed boost, reduces the memory your program will eat, and is just a cool solution to the problem in general.

Have fun getting it to work.

Share this post


Link to post
Share on other sites

Like this (doing an array solution this time)

Dim $strings[5]=["hi","hello","hej","hallo","ola"]
$strings=_RandomizeArray($strings)

Local $count=0
While 1
    Sleep(100)
    Send($strings[$count])
    $count+=1
    If $count=Ubound($strings)-1 Then
        $strings=_RandomizeArray($strings)
        $count=0
    EndIf
WEnd


Func _RandomizeArray($array)
    Local $out[Ubound($array)]
    For $element In $array
        Do
            $i=Random(0,Ubound($out)-1,1)
        Until $out[$i]=""
        $out[$i]=$element
    Next
    Return $out
EndFunc

This also works for numbers of course.

:)


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Well, monoceres, that will work, but it can take a lot of time, if your Random keeps picking locations that already have data in them, which can happen if you get down to the last few elements in the input array. Also, if the value in the input array was "", and is picked again, your going to overwrite it (but, that would just leave some other location at "", so that's not too bad).

That's the main reason I did mine with a changing random function, to avoid times where it might run fast, and then the next time take a lot longer to finish.

Share this post


Link to post
Share on other sites

I believe this is faster:

; More levels = better shuffling but slower execution time.
Func _RandomizeArray(ByRef $array, $level=3)
    Local $size=Ubound($array)
    
    For $crap=1 To $level
        For $i=0 To $size-1
            $rand=Random(0,$size-1,1)
            $temp=$array[$i]
            $array[$i]=$array[$rand]
            $array[$rand]=$temp
        Next
    Next
EndFunc

But the shuffling could be quite bad considering an element could be moved back and forth to the same position it original had.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Couldn't that also happen in real life? I could shuffle a deck 100 times, and a card in it could end up right back in it's original starting location.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Couldn't that also happen in real life? I could shuffle a deck 100 times, and a card in it could end up right back in it's original starting location.

Yeah, but I wouldn't consider shuffling card in real life as real random, but for card shuffling algorithms, fine.

I used the swap algorithm for my solitaire game in my sig for example (The Idiot).

:)

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

If you don't consider shuffling in real life as real random, what do you consider real random? Would rolling dice to put the cards in order be more random? Same thing could happen there.

Not trying to argue with you, but the general perception of randomness most people have is horribly wrong.

Share this post


Link to post
Share on other sites

If you don't consider shuffling in real life as real random, what do you consider real random? Would rolling dice to put the cards in order be more random? Same thing could happen there.

Not trying to argue with you, but the general perception of randomness most people have is horribly wrong.

Something that is not affected by humans for starters. Humans are terrible at generating random stuff (just look at my grandma when she's shuffling the cards, no random there).

A well known random generator is a geiger counter. I guess I consider it a very good random generator.

I don't think there are any true random because everything happens because something else affected it, therefore if every possible parameter is known in a case, then it can be foreseen and thus not making it true random.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Here's the version that uses the faster algorithm, it works...

Dim $strings[5]=["hi","hello","hej","hallo","ola"]
_RandomizeArray($strings)

Local $count=0
While 1
    Sleep(100)
    Send($strings[$count])
    $count+=1
    If $count=Ubound($strings)+1 Then
        _RandomizeArray($strings)
        $count=0
        exit
    EndIf
WEnd


; More levels = better shuffling but slower execution time.
Func _RandomizeArray(ByRef $array, $level=3)
    Local $size=Ubound($array)
    
    For $crap=1 To $level
        For $i=0 To $size-1
            $rand=Random(0,$size-1,1)
            $temp=$array[$i]
            $array[$i]=$array[$rand]
            $array[$rand]=$temp
        Next
    Next
EndFunc

:)


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0