Jump to content
Sign in to follow this  
niubbone

Custom random function

Recommended Posts

niubbone

hi all..

Honestly i'm getting tired of this, every project i make, there is always some kind of problem...

now, i made a customized random number generator.

Someone has an explanation why this get stuck infinitely?

$R2=Randomize(10100,113210)
MsgBox(0,"Random",$R2)
Func Randomize($Val1,$Val2)
$RandF1=@MSEC
$RandF2=@MSEC*(@MIN/$RandF1/10)
$RandF3=@YDAY/@Min*($RandF1/10)
$Numero=$RandF1*$RandF1/@MSEC
    While 1
        If $Numero<$Val1 Then
            Do
                $Numero=$Numero*$RandF2
            Until $Numero>=$Val1
        ElseIf $Numero>$Val2 Then
            Do
                $Numero=$Numero/$RandF3
            Until $Numero<=$Val2
        Else
            ExitLoop
        EndIf
        WEnd
EndFunc

Share this post


Link to post
Share on other sites
sahsanu

Someone has an explanation why this get stuck infinitely?

I don't know what do you mean with stuck infinetly, your program runs but always returns 0 because of you don't Return anything. Try to put Return $Numero before the exitloop or before EndFunc.

;...
Else
   Return $Numero
   ExitLoop
EndIf
;...

Edit: See below and pay attention to jchd's post, it is a wonderful explanation.

Edited by sahsanu

Share this post


Link to post
Share on other sites
jchd

I really don't get it!

AutoIt devs carefully selected one of the very best PRNG (pseudo-random number generator) available but still you want to write you own.

PRNGs are probably among the most difficult things to write, ever, and the one in AutoIt makes no exception. It was written by _specialized_ _professional_ _mathematicians_ reviewed by peers, submitted to drastic tests you have no idea how they can discriminate between good and bad PRNGs, published in academic journal, carefully examined and scrutinized by worldwide specialists and, AFAIK, still stands the (huge) expectations people put in it. And, even with all that care, it could be proven dumb wrong tomorrow.

As Melba23 often says, there is no shame to have as being a noob. We all were noobs to programming, and even noobs to walking.

But you really should be spending more time and energy learning how to program than trying to figure anything that hard.

Now to answer your question, look at what you write!

Then, looking at what it does, we have a few assignments in a row, which are likely to occur in a very short fraction of the same second, with high probability:

$RandF1 = @MSEC

OK

$RandF2 = @MSEC * (@MIN / $RandF1 / 10)

with $RandF1 = @MSEC, that gives (with high probability)

$RandF2 = @MSEC / @MSEC * @MIN *10

that is:

$RandF2=@MIN *10

Now we have:

$RandF3 = @YDAY / @Min * ($RandF1 / 10)

with $RandF1 = @MSEC, that gives (with high probability)

$RandF3 = (@YDAY * @MSEC) / (@Min * 10)

Now, the "seed":

$Numero = $RandF1 * $RandF1 / @MSEC

with $RandF1 = @MSEC, that gives (with high probability)

$Numero = @MSEC * @MSEC / @MSEC

that is:

$Numero = @MSEC

Now the loops: fasten your seatbelt!

$Numero = $Numero * $RandF2

What will that do when $Numero = 0 or 1 , OR when $RandF2 = 0 or 1 ???

$Numero = $Numero / $RandF3

Same questions!

In short, the conditions in your Do..Until may well never be met.

But that's not the only problem!

Your function doesn't return anything, so if it ever terminates, it will always return the default value: zero. How random!

That simple call would do what you want in the first place, way faster and with no trap, giving you a decently PR number:

Local $R2 = Random(10100, 113210, 1)

if you wanted integers

Local $R2 = Random() * (113210 - 10100) + 10100

if you wanted a floating-point value in [10100, 113210[ (subject to classical rounding).

Finally, _no_ PRNG uses something based on any computer clock.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
niubbone

Well, why I would like to make a random generator myself? Because the one give doesn't allow a simple task: to take a set of random numbers not picking the same numbers.

It's 3 weeks I am trying to get out of this code and I am became so mad that i thought to make a random number generator myself (I know it doesn't do what i said, but first i was going to make it work, then the rest).

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Local $GUITestLavoro = GUICreate("Test Colloquio Lavorativo", 468, 643, 402, 7)
                                GUICtrlCreateLabel("TEST DI IDONEITA' AL POSTO DI LAVORO", 48, 16, 377, 28)
                                GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
                                GUICtrlCreateLabel("Mi raccomando, non faccia il coglione come al suo solito....", 104, 56, 282, 17)
                                GUICtrlCreateLabel("1)", 8, 88, 17, 22)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUIStartGroup()
                                Local $LabelRadioDom1 = GUICtrlCreateLabel("dom1", 32, 88, 30, 17)
                                Local $Radio1 = GUICtrlCreateRadio("Radio1", 8, 112, 425, 17)
                                Local $Radio2 = GUICtrlCreateRadio("Radio2", 8, 136, 425, 17)
                                Local $Radio3 = GUICtrlCreateRadio("Radio3", 8, 160, 425, 17)
                                Local $Radio4 = GUICtrlCreateRadio("Radio4", 8, 184, 425, 17)
                                GUICtrlCreateLabel("2)", 12, 211, 17, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUIStartGroup()
                                Local $LabelRadioDom2 = GUICtrlCreateLabel("dom2", 36, 211, 30, 17)
                                Local $Radio5 = GUICtrlCreateRadio("Radio1b", 12, 235, 425, 17)
                                Local $Radio6 = GUICtrlCreateRadio("Radio2b", 12, 259, 425, 17)
                                Local $Radio7 = GUICtrlCreateRadio("Radio3b", 12, 283, 425, 17)
                                Local $Radio8 = GUICtrlCreateRadio("Radio4b", 12, 307, 425, 17)
                                GUICtrlCreateLabel("3)", 12, 340, 17, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUIStartGroup()
                                Local $LabelRadioDom3 = GUICtrlCreateLabel("dom3", 36, 340, 30, 17)
                                Local $Radio9 = GUICtrlCreateRadio("Radio1c", 12, 364, 425, 17)
                                Local $Radio10 = GUICtrlCreateRadio("Radio2c", 12, 388, 425, 17)
                                Local $Radio11 = GUICtrlCreateRadio("Radio3c", 12, 412, 425, 17)
                                Local $Radio12 = GUICtrlCreateRadio("Radio4c", 12, 436, 425, 17)
                                GUICtrlCreateLabel("4)", 12, 462, 17, 20)
                                GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
                                GUIStartGroup()
                                Local $LabelRadioDom4 = GUICtrlCreateLabel("dom4", 36, 462, 30, 17)
                                Local $Radio13 = GUICtrlCreateRadio("Radio1d", 12, 486, 425, 17)
                                Local $Radio14 = GUICtrlCreateRadio("Radio2d", 12, 510, 425, 17)
                                Local $Radio15 = GUICtrlCreateRadio("Radio3d", 12, 534, 425, 17)
                                Local $Radio16 = GUICtrlCreateRadio("Radio4d", 12, 558, 425, 17)
                                Local $BottoneScappaTest = GUICtrlCreateButton("Scappa....", 8, 592, 177, 41, $WS_GROUP)
                                Local $BottoneConsegnaTest = GUICtrlCreateButton("Consegna il test", 280, 592, 177, 41, $WS_GROUP)
                                Local $CompilaTest=ColloquioDomande()
                                GUICtrlSetData($LabelRadioDom1,$CompilaTest[0][0])
                                GUICtrlSetData($LabelRadioDom2,$CompilaTest[0][1])
                                GUICtrlSetData($LabelRadioDom3,$CompilaTest[0][2])
                                GUICtrlSetData($LabelRadioDom4,$CompilaTest[0][3])
                                GUICtrlSetData($Radio1,$CompilaTest[1][0])
                                GUICtrlSetData($Radio2,$CompilaTest[1][1])
                                GUICtrlSetData($Radio3,$CompilaTest[1][2])
                                GUICtrlSetData($Radio4,$CompilaTest[1][3])
                                GUICtrlSetData($Radio5,$CompilaTest[1][4])
                                GUICtrlSetData($Radio6,$CompilaTest[1][5])
                                GUICtrlSetData($Radio7,$CompilaTest[1][6])
                                GUICtrlSetData($Radio8,$CompilaTest[1][7])
                                GUICtrlSetData($Radio9,$CompilaTest[1][8])
                                GUICtrlSetData($Radio10,$CompilaTest[1][9])
                                GUICtrlSetData($Radio11,$CompilaTest[1][10])
                                GUICtrlSetData($Radio12,$CompilaTest[1][11])
                                GUICtrlSetData($Radio13,$CompilaTest[1][12])
                                GUICtrlSetData($Radio14,$CompilaTest[1][13])
                                GUICtrlSetData($Radio15,$CompilaTest[1][14])
                                GUICtrlSetData($Radio16,$CompilaTest[1][15])
                                GUISetState(@SW_SHOW)
                                While 1
                                    $nMsg = GUIGetMsg()
                                    Switch $nMsg
                                        Case $GUI_EVENT_CLOSE
                                            ExitLoop
                                        Case $BottoneScappaTest
                                            Exitloop

                                    EndSwitch
                                WEnd
Func ColloquioDomande()
    Local $DomandaA[5]=["domA","a1","a2","a3","a4"],$DomandaB[5]=["domB","b1","b2","b3","b4"],$DomandaC[5]=["domC","c1","c2","c3","c4"] _
    ,$DomandaD[5]=["domD","d1","d2","d3","d4"],$DomandaE[5]=["domE","e1","e2","e3","e4"]
    Local $DomandeDifferenti[4]
    Local $RisposteMischiate[16]
    Local $i=1
    Local $r=4
    For $z=1 To 4
        Local $numeridom[5]=[1,2,3,4,5]
        Local $GiroDomande=$numeridom[Random(0,UBound($numeridom)-1,1)]
        MsgBox(0,"e",$GiroDomande)
        _ArrayDelete($numeridom,$GiroDomande-1)
         Select
            Case $GiroDomande=1
                $DomandeDifferenti[$z-1]=$DomandaA[0]
                If $DomandaA[0]="DomA" Then
                _ArrayDelete($DomandaA,0)
            else
                ContinueCase
                EndIf
                Local $RisposteInOrdine[4]=[$DomandaA[0],$DomandaA[1],$DomandaA[2],$DomandaA[3]]
            Case $GiroDomande=2
                $DomandeDifferenti[$z-1]=$DomandaB[0]
                If $DomandaB[0]="DomB" Then
                _ArrayDelete($DomandaB,0)
                else
                ContinueCase
                EndIf
                Local $RisposteInOrdine[4]=[$DomandaB[0],$DomandaB[1],$DomandaB[2],$DomandaB[3]]
            Case $GiroDomande=3
                $DomandeDifferenti[$z-1]=$DomandaC[0]
                If $DomandaC[0]="DomC" Then
                _ArrayDelete($DomandaC,0)
                else
                ContinueCase
                EndIf
                Local $RisposteInOrdine[4]=[$DomandaC[0],$DomandaC[1],$DomandaC[2],$DomandaC[3]]
            Case $GiroDomande=4
                $DomandeDifferenti[$z-1]=$DomandaD[0]
                If $DomandaD[0]="DomD" Then
                _ArrayDelete($DomandaD,0)
                else
                ContinueCase
                EndIf
                Local $RisposteInOrdine[4]=[$DomandaD[0],$DomandaD[1],$DomandaD[2],$DomandaD[3]]
            Case $GiroDomande=5
                $DomandeDifferenti[$z-1]=$DomandaE[0]
                If $DomandaE[0]="DomE" Then
                _ArrayDelete($DomandaE,0)
                else
                ContinueCase
                Endif
                Local $RisposteInOrdine[4]=[$DomandaE[0],$DomandaE[1],$DomandaE[2],$DomandaE[3]]
            Case $GiroDomande
                $DomandeDifferenti[$z-1]="DomRiserva"
                Local $RisposteInOrdine[4]
                $RisposteInOrdine[0]="RisA"
                $RisposteInOrdine[1]="RisB"
                $RisposteInOrdine[2]="RisC"
                $RisposteInOrdine[3]="RisD"
        EndSelect
        For $k=$i To $r
            Local $numeririsp[4]=[0,1,2,3]
            Local $CopiaRispOrdine=$RisposteInOrdine
            Local $GiroRispInOrdine=$numeririsp[Random(0,Ubound($numeririsp)-1,1)]
            MsgBox(0,"w",$GiroRispInOrdine)
            _ArrayDelete($numeririsp,$GiroRispInOrdine)
            $RisposteMischiate[$k-1]=$CopiaRispOrdine[$GiroRispInOrdine]
            _ArrayDelete($CopiaRispOrdine,$GiroRispInOrdine)
        Next
        $i+=4
        $r+=4
    Next
    Local $MultiDomERisp[2][16]=[[$DomandeDifferenti[0],$DomandeDifferenti[1],$DomandeDifferenti[2],$DomandeDifferenti[3]], _
    [$RisposteMischiate[0],$RisposteMischiate[1],$RisposteMischiate[2],$RisposteMischiate[3],$RisposteMischiate[4], _
    $RisposteMischiate[5],$RisposteMischiate[6],$RisposteMischiate[7],$RisposteMischiate[8],$RisposteMischiate[9], _
    $RisposteMischiate[10],$RisposteMischiate[11],$RisposteMischiate[12],$RisposteMischiate[13],$RisposteMischiate[14], _
    $RisposteMischiate[15]]]
    Return $MultiDomERisp
EndFunc

I have simply to fill that damn test with 4 random questions and to be sure that the replies are taken from the correspoding set of replies and randomized every time.

It's 3 week I am trying and can't get out with a satisfying result. I've changed countless times the code and can't arrive at a solution. To make a different set of random numbers i tried to pick numbers from an array of numbers, then deleting it, but it seems useless. Now, can you find a solution to this? because i wasn't able to, and i asked to friends, in this forum, and in other forums, and noone seemed to be able to.

PS: To immediately get the grip of the problem, try to run it a few times (and if needed to remove the message boxes) and check the result a few times.

Edited by niubbone

Share this post


Link to post
Share on other sites
MvGulik
whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites
Malkey

Try this.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Local $GUITestLavoro = GUICreate("Test Colloquio Lavorativo", 468, 643, 402, 7)
GUICtrlCreateLabel("TEST DI IDONEITA' AL POSTO DI LAVORO", 48, 16, 377, 28)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel("Mi raccomando, non faccia il coglione come al suo solito....", 104, 56, 282, 17)
GUICtrlCreateLabel("1)", 8, 88, 17, 22)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUIStartGroup()
Local $LabelRadioDom1 = GUICtrlCreateLabel("dom1", 32, 88, 30, 17)
Local $Radio1 = GUICtrlCreateRadio("Radio1", 8, 112, 425, 17)
Local $Radio2 = GUICtrlCreateRadio("Radio2", 8, 136, 425, 17)
Local $Radio3 = GUICtrlCreateRadio("Radio3", 8, 160, 425, 17)
Local $Radio4 = GUICtrlCreateRadio("Radio4", 8, 184, 425, 17)
GUICtrlCreateLabel("2)", 12, 211, 17, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUIStartGroup()
Local $LabelRadioDom2 = GUICtrlCreateLabel("dom2", 36, 211, 30, 17)
Local $Radio5 = GUICtrlCreateRadio("Radio1b", 12, 235, 425, 17)
Local $Radio6 = GUICtrlCreateRadio("Radio2b", 12, 259, 425, 17)
Local $Radio7 = GUICtrlCreateRadio("Radio3b", 12, 283, 425, 17)
Local $Radio8 = GUICtrlCreateRadio("Radio4b", 12, 307, 425, 17)
GUICtrlCreateLabel("3)", 12, 340, 17, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUIStartGroup()
Local $LabelRadioDom3 = GUICtrlCreateLabel("dom3", 36, 340, 30, 17)
Local $Radio9 = GUICtrlCreateRadio("Radio1c", 12, 364, 425, 17)
Local $Radio10 = GUICtrlCreateRadio("Radio2c", 12, 388, 425, 17)
Local $Radio11 = GUICtrlCreateRadio("Radio3c", 12, 412, 425, 17)
Local $Radio12 = GUICtrlCreateRadio("Radio4c", 12, 436, 425, 17)
GUICtrlCreateLabel("4)", 12, 462, 17, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUIStartGroup()
Local $LabelRadioDom4 = GUICtrlCreateLabel("dom4", 36, 462, 30, 17)
Local $Radio13 = GUICtrlCreateRadio("Radio1d", 12, 486, 425, 17)
Local $Radio14 = GUICtrlCreateRadio("Radio2d", 12, 510, 425, 17)
Local $Radio15 = GUICtrlCreateRadio("Radio3d", 12, 534, 425, 17)
Local $Radio16 = GUICtrlCreateRadio("Radio4d", 12, 558, 425, 17)
Local $BottoneScappaTest = GUICtrlCreateButton("Scappa....", 8, 592, 177, 41, $WS_GROUP)
Local $BottoneConsegnaTest = GUICtrlCreateButton("Consegna il test", 280, 592, 177, 41, $WS_GROUP)
Local $CompilaTest = ColloquioDomande()
GUICtrlSetData($LabelRadioDom1, $CompilaTest[0][0])
GUICtrlSetData($LabelRadioDom2, $CompilaTest[0][1])
GUICtrlSetData($LabelRadioDom3, $CompilaTest[0][2])
GUICtrlSetData($LabelRadioDom4, $CompilaTest[0][3])
GUICtrlSetData($Radio1, $CompilaTest[1][0])
GUICtrlSetData($Radio2, $CompilaTest[1][1])
GUICtrlSetData($Radio3, $CompilaTest[1][2])
GUICtrlSetData($Radio4, $CompilaTest[1][3])
GUICtrlSetData($Radio5, $CompilaTest[1][4])
GUICtrlSetData($Radio6, $CompilaTest[1][5])
GUICtrlSetData($Radio7, $CompilaTest[1][6])
GUICtrlSetData($Radio8, $CompilaTest[1][7])
GUICtrlSetData($Radio9, $CompilaTest[1][8])
GUICtrlSetData($Radio10, $CompilaTest[1][9])
GUICtrlSetData($Radio11, $CompilaTest[1][10])
GUICtrlSetData($Radio12, $CompilaTest[1][11])
GUICtrlSetData($Radio13, $CompilaTest[1][12])
GUICtrlSetData($Radio14, $CompilaTest[1][13])
GUICtrlSetData($Radio15, $CompilaTest[1][14])
GUICtrlSetData($Radio16, $CompilaTest[1][15])
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $BottoneScappaTest
            ExitLoop

    EndSwitch
WEnd

Func ColloquioDomande()
    Local $DomandaA[5] = ["domA", "a1", "a2", "a3", "a4"], $DomandaB[5] = ["domB", "b1", "b2", "b3", "b4"], $DomandaC[5] = ["domC", "c1", "c2", "c3", "c4"] _
            , $DomandaD[5] = ["domD", "d1", "d2", "d3", "d4"], $DomandaE[5] = ["domE", "e1", "e2", "e3", "e4"]
    Local $aArrays[5] = [$DomandaA, $DomandaB, $DomandaC, $DomandaD, $DomandaE]
    _ArrayShuffle($aArrays)

    Local $MultiDomERisp[2][16], $aTemp, $num = 0
    For $iArrNo = 0 To 3
        $aTemp = $aArrays[$iArrNo]
        _ArrayShuffle($aTemp, 1)
        $MultiDomERisp[0][$iArrNo] = $aTemp[0]
        For $x = 1 To UBound($aTemp) - 1
            $MultiDomERisp[1][$num] = $aTemp[$x]
            $num += 1
        Next
    Next
    Return $MultiDomERisp
EndFunc ;==>ColloquioDomande

; http://www.autoitscript.com/forum/index.php?s=&showtopic=79564&view=findpost&p=573531
Func _ArrayShuffle(ByRef $aArray, $iBase = 0, $iUBound = Default)
    If Not IsArray($aArray) Then Return SetError(1, 0, 0)
    If UBound($aArray, 0) <> 1 Then Return SetError(2, 0, 0)

    Local $temp, $rand
    If $iUBound = Default Or $iUBound = 0 Then $iUBound = UBound($aArray) - 1
    For $i = $iBase To $iUBound
        $temp = $aArray[$i]
        $rand = Random($iBase, $iUBound, 1)
        $aArray[$i] = $aArray[$rand]
        $aArray[$rand] = $temp
    Next
EndFunc ;==>_ArrayShuffle

....

Local $R2 = Random() * (113210 - 10100) + 10100

if you wanted a floating-point value in [10100, 113210[ (subject to classical rounding).

....

Also, Local $R2 = Random(10100, 113210) returns a floating-point value.

Share this post


Link to post
Share on other sites
jchd

@nuibbone,

What you're after isn't called a random number generator. What you want is a random permutation of integers.

What makes it not random is that you say "not picking the same numbers" and that's absolutely against any notion of random.

To see that, pick a perfect dice and imagine to roll it several times. The first roll _is_ random, but none of the subsequent are.

The subject was discussed here before. In the context of deck shuffling (or equivalent) or in a more general (large range) framework.

Google "random permutation" for a background.

In general, Knuth (or rather Fisher - Yates) algorithm gives near optimal result. Read my post on this subject for a remark anyway.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
niubbone

Try this.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Local $GUITestLavoro = GUICreate("Test Colloquio Lavorativo", 468, 643, 402, 7)
GUICtrlCreateLabel("TEST DI IDONEITA' AL POSTO DI LAVORO", 48, 16, 377, 28)
GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif")
GUICtrlCreateLabel("Mi raccomando, non faccia il coglione come al suo solito....", 104, 56, 282, 17)
GUICtrlCreateLabel("1)", 8, 88, 17, 22)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUIStartGroup()
Local $LabelRadioDom1 = GUICtrlCreateLabel("dom1", 32, 88, 30, 17)
Local $Radio1 = GUICtrlCreateRadio("Radio1", 8, 112, 425, 17)
Local $Radio2 = GUICtrlCreateRadio("Radio2", 8, 136, 425, 17)
Local $Radio3 = GUICtrlCreateRadio("Radio3", 8, 160, 425, 17)
Local $Radio4 = GUICtrlCreateRadio("Radio4", 8, 184, 425, 17)
GUICtrlCreateLabel("2)", 12, 211, 17, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUIStartGroup()
Local $LabelRadioDom2 = GUICtrlCreateLabel("dom2", 36, 211, 30, 17)
Local $Radio5 = GUICtrlCreateRadio("Radio1b", 12, 235, 425, 17)
Local $Radio6 = GUICtrlCreateRadio("Radio2b", 12, 259, 425, 17)
Local $Radio7 = GUICtrlCreateRadio("Radio3b", 12, 283, 425, 17)
Local $Radio8 = GUICtrlCreateRadio("Radio4b", 12, 307, 425, 17)
GUICtrlCreateLabel("3)", 12, 340, 17, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUIStartGroup()
Local $LabelRadioDom3 = GUICtrlCreateLabel("dom3", 36, 340, 30, 17)
Local $Radio9 = GUICtrlCreateRadio("Radio1c", 12, 364, 425, 17)
Local $Radio10 = GUICtrlCreateRadio("Radio2c", 12, 388, 425, 17)
Local $Radio11 = GUICtrlCreateRadio("Radio3c", 12, 412, 425, 17)
Local $Radio12 = GUICtrlCreateRadio("Radio4c", 12, 436, 425, 17)
GUICtrlCreateLabel("4)", 12, 462, 17, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUIStartGroup()
Local $LabelRadioDom4 = GUICtrlCreateLabel("dom4", 36, 462, 30, 17)
Local $Radio13 = GUICtrlCreateRadio("Radio1d", 12, 486, 425, 17)
Local $Radio14 = GUICtrlCreateRadio("Radio2d", 12, 510, 425, 17)
Local $Radio15 = GUICtrlCreateRadio("Radio3d", 12, 534, 425, 17)
Local $Radio16 = GUICtrlCreateRadio("Radio4d", 12, 558, 425, 17)
Local $BottoneScappaTest = GUICtrlCreateButton("Scappa....", 8, 592, 177, 41, $WS_GROUP)
Local $BottoneConsegnaTest = GUICtrlCreateButton("Consegna il test", 280, 592, 177, 41, $WS_GROUP)
Local $CompilaTest = ColloquioDomande()
GUICtrlSetData($LabelRadioDom1, $CompilaTest[0][0])
GUICtrlSetData($LabelRadioDom2, $CompilaTest[0][1])
GUICtrlSetData($LabelRadioDom3, $CompilaTest[0][2])
GUICtrlSetData($LabelRadioDom4, $CompilaTest[0][3])
GUICtrlSetData($Radio1, $CompilaTest[1][0])
GUICtrlSetData($Radio2, $CompilaTest[1][1])
GUICtrlSetData($Radio3, $CompilaTest[1][2])
GUICtrlSetData($Radio4, $CompilaTest[1][3])
GUICtrlSetData($Radio5, $CompilaTest[1][4])
GUICtrlSetData($Radio6, $CompilaTest[1][5])
GUICtrlSetData($Radio7, $CompilaTest[1][6])
GUICtrlSetData($Radio8, $CompilaTest[1][7])
GUICtrlSetData($Radio9, $CompilaTest[1][8])
GUICtrlSetData($Radio10, $CompilaTest[1][9])
GUICtrlSetData($Radio11, $CompilaTest[1][10])
GUICtrlSetData($Radio12, $CompilaTest[1][11])
GUICtrlSetData($Radio13, $CompilaTest[1][12])
GUICtrlSetData($Radio14, $CompilaTest[1][13])
GUICtrlSetData($Radio15, $CompilaTest[1][14])
GUICtrlSetData($Radio16, $CompilaTest[1][15])
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $BottoneScappaTest
            ExitLoop

    EndSwitch
WEnd

Func ColloquioDomande()
    Local $DomandaA[5] = ["domA", "a1", "a2", "a3", "a4"], $DomandaB[5] = ["domB", "b1", "b2", "b3", "b4"], $DomandaC[5] = ["domC", "c1", "c2", "c3", "c4"] _
            , $DomandaD[5] = ["domD", "d1", "d2", "d3", "d4"], $DomandaE[5] = ["domE", "e1", "e2", "e3", "e4"]
    Local $aArrays[5] = [$DomandaA, $DomandaB, $DomandaC, $DomandaD, $DomandaE]
    _ArrayShuffle($aArrays)

    Local $MultiDomERisp[2][16], $aTemp, $num = 0
    For $iArrNo = 0 To 3
        $aTemp = $aArrays[$iArrNo]
        _ArrayShuffle($aTemp, 1)
        $MultiDomERisp[0][$iArrNo] = $aTemp[0]
        For $x = 1 To UBound($aTemp) - 1
            $MultiDomERisp[1][$num] = $aTemp[$x]
            $num += 1
        Next
    Next
    Return $MultiDomERisp
EndFunc ;==>ColloquioDomande

; http://www.autoitscript.com/forum/index.php?s=&showtopic=79564&view=findpost&p=573531
Func _ArrayShuffle(ByRef $aArray, $iBase = 0, $iUBound = Default)
    If Not IsArray($aArray) Then Return SetError(1, 0, 0)
    If UBound($aArray, 0) <> 1 Then Return SetError(2, 0, 0)

    Local $temp, $rand
    If $iUBound = Default Or $iUBound = 0 Then $iUBound = UBound($aArray) - 1
    For $i = $iBase To $iUBound
        $temp = $aArray[$i]
        $rand = Random($iBase, $iUBound, 1)
        $aArray[$i] = $aArray[$rand]
        $aArray[$rand] = $temp
    Next
EndFunc ;==>_ArrayShuffle

Also, Local $R2 = Random(10100, 113210) returns a floating-point value.

Surely the most helpful. Many thanks man. Awesome.

By the way I still have to figure out how this works.

#Include <Array.au3>

Dim $Data[10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

_ArrayDisplay($Data)
For $i = 1 To 100
    $A = Random(0, UBound($Data) - 1, 1)
    $B = Random(0, UBound($Data) - 1, 1)
    $Temp = $Data[$A]
    $Data[$A] = $Data[$B]
    $Data[$B] = $Temp
Next
_ArrayDisplay($Data)

Seems simple but I don't get how it works...

Share this post


Link to post
Share on other sites
jchd

That version works by exchanging couples of random entries in an array filled with intergers.

It's by far inferior to the (way more efficient and provable) Knuth algorithm I mentionned above.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.