Jump to content



Photo

How to Output a Random Sequence of Numbers?


  • Please log in to reply
3 replies to this topic

#1 ithelast

ithelast

    Seeker

  • Normal Members
  • 7 posts

Posted 06 July 2012 - 06:42 PM

I am trying to input three numbers (1,2,3 for example) into a form in a random order. Currently I am manually sending this information as follows:


Send("1") Send("3") Send("2")


Very simple but not random at all. I would like to be able to send these in a random order each time.





#2 gcue

gcue

    just a wannabe

  • Active Members
  • PipPipPipPipPipPip
  • 1,629 posts

Posted 06 July 2012 - 06:45 PM

for $x = 1 to 3 ConsoleWrite(Random(1,3, 1) & @CRLF) next


you can replace consolewrite with send

Edited by gcue, 06 July 2012 - 06:46 PM.


#3 czardas

czardas

  • Active Members
  • PipPipPipPipPipPip
  • 5,065 posts

Posted 06 July 2012 - 07:06 PM

#include <Array.au3> Dim $array[3] = [1,2,3] $array = _ArrayPermute($array) For $i = 1 To 100     ConsoleWrite($array[Random(1, $array[0], 1)] & @LF) Next


#4 gcue

gcue

    just a wannabe

  • Active Members
  • PipPipPipPipPipPip
  • 1,629 posts

Posted 06 July 2012 - 07:29 PM

props to tom and yashield

Plain Text         
#include <array.au3> Dim $numbers[3] = [1, 2, 3] _ArrayRandom($numbers) For $x = 0 To UBound($numbers) - 1     ConsoleWrite($numbers[$x] & @CRLF) Next ; #FUNCTION# ==================================================================================================================== ; Name...........: _ArrayRandom ; Description ...: Randomize the row order of (part of) a 1D or 2D array. ; Syntax.........: _ArrayRandom(ByRef $avArray, $iStart = 0, $iEnd = 0) ; Parameters ....: $avArray  - Array to randomize ;               $iStart  - [optional] Index of array to start at ;               $iEnd   - [optional] Index of array to stop at ; Return values .: Success - 1 ;               Failure - 0, sets @error: ;               |1 - $avArray is not an array ;               |2 - $iStart is greater than $iEnd ; Author ........: Tom Vernooij ; Modified.......: ; Remarks .......: Based on Yashied's method ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _ArrayRandom(ByRef $avArray, $iStart = 0, $iEnd = 0)     If Not IsArray($avArray) Then Return SetError(1, 0, 0)     Local $iRow, $iCol, $rRow, $Temp, $numCols = UBound($avArray, 2), $Ubound = UBound($avArray) - 1     ; Bounds checking     If $iEnd < 1 Or $iEnd > $Ubound Then $iEnd = $Ubound     If $iStart < 0 Then $iStart = 0     If $iStart > $iEnd Then Return SetError(2, 0, 0)     ; for 2 dimentional arrays:     If $numCols Then         For $iRow = $iStart To $iEnd ;for each row...             $rRow = Random($iStart, $iEnd, 1) ;...select a random row             For $iCol = 0 To $numCols - 1 ;swich the values for each cell in the rows                 $Temp = $avArray[$iRow][$iCol]                 $avArray[$iRow][$iCol] = $avArray[$rRow][$iCol]                 $avArray[$rRow][$iCol] = $Temp             Next         Next         ; for 1 dimentional arrays:     Else         For $iRow = $iStart To $iEnd ;for each cell...             $rRow = Random($iStart, $iEnd, 1) ;...select a random cell             $Temp = $avArray[$iRow] ;switch the values in the cells             $avArray[$iRow] = $avArray[$rRow]             $avArray[$rRow] = $Temp         Next     EndIf     Return 1 EndFunc   ;==>_ArrayRandom

Edited by gcue, 06 July 2012 - 07:43 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users