Jump to content

Randomize the Order!


Wolvereness
 Share

Recommended Posts

1 parameter, just the number of elements to be randomized ;-)

It returns an array starting with $*[1] being the first number returned.

wRandomize(number)

Func wRandomize($wNumber)
    Dim $wRandomized[$wNumber + 1], $wRandomize[$wNumber + 1], $wRandomizing[$wNumber + 1]
    $wRandomized[0] = $wNumber
    For $wRandomizeCount = 1 To $wNumber
        $wRandomize[$wRandomizeCount] = 0
    Next
    For $wCountZ = 1 To $wNumber
        $wRandomizing[0] = 0
        For $wCountY = 1 To $wNumber
            If $wRandomize[$wCountY] Then
                ContinueLoop
            Else
                $wRandomizing[0] = $wRandomizing[0] + 1
                $wRandomizing[$wRandomizing[0]] = $wCountY
            EndIf
        Next
        If $wRandomizing[0] = 1 Then
            $wRandom = 1
        Else
            $wRandom = wRandom(1, $wRandomizing[0])
        EndIf
        $wRandomize[$wRandomizing[$wRandom]] = 1
        $wRandomized[$wCountZ] = $wRandomizing[$wRandom]
    Next
    Return $wRandomized
EndFunc  ;==>wRandomize
Func wRandom($wRandomMin, $wRandomMax)
    If StringInStr($wRandomMin & $wRandomMax, '.') = 0 Then
        Return Round(Random($wRandomMin - 1 & '.5', $wRandomMax & '.5'), 0)
    Else
        Return ''
        SetError(1)
    EndIf
EndFunc  ;==>wRandom

Edit: OOPS!!! I used $x without knowing it (yikes)

Edited by Wolvereness

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

Link to comment
Share on other sites

For a few seconds, I thought this was a string randomizer, but it's really a number randomizer.

You could use the numbers to assign to the strings though so they have a random order :idiot:

Good work, but I think people should aways post an example to help clueless people out. So i'll post a quick one up for you.

$random = wRandomize("5")

For $i = 1 to 5
   MsgBox(0, "Prompt", $random[$i])
Next
Link to comment
Share on other sites

well, could you explain how yours is so much faster then mine?

Mine just makes a new array and assures that your gonna get a good number with random.

It remakes the array each time. I'm amazed...

Oh yeah, i just noticed that yours is not AS random as mine ;-)

This is more random

Round(Random($wRandomMin - 1 & '.5', $wRandomMax & '.5'), 0)
then
Int(Random(1,$LR_n))

Damnit, I forgot

@killaz219

This will make it randomize a string:

$x = 'something to randomize'
$v = StringLen($x)
$w = ''
$y = wRandomize($v)
   MsgBox(0,'-',$x)

For $z = 1 to $v
   $w = $w & StringMid($x, $y[$z], 1)
Next
MsgBox(0, '', $w)
Edited by Wolvereness

Offering any help to anyone (to my capabilities of course)Want to say thanks? Click here! [quote name='Albert Einstein']Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.[/quote][quote name='Wolvereness' date='7:35PM Central, Jan 11, 2005']I'm NEVER wrong, I call it something else[/quote]

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...