Guten Abend!
Ich habe ein kleines Problem, undzwar möchte ich in einer .txt Datei mit 650 Zeilen, diese Zeilen durcheinander bringen. Es handelt sich hierbei um einen Mapcycle von CSPSP, der Alphabetisch geordnet ist. Allerdings sind dann z.B. alle AWP Maps hintereinander, und das möchte ich nicht. Ich weiß nicht wo ich anfangen soll. Ich dachte irgendwie an soetwas Ähnliches, als wenn man jede Zeile ausliest und in eine Andere schreibt.
Könnt ihr mir da vielleicht helfen? Und bevor nachgefragt wird: Einen Code zum posten habe ich noch nicht.
Zeilen in .txt durcheinander bringen
-
- [ offen ]
-
Hugbert -
23. Dezember 2011 um 22:20 -
Geschlossen -
Erledigt
-
-
Mal was ganz simples.
[autoit]#include <Array.au3>
[/autoit][autoit][/autoit][autoit];Global $sPath = "c:\irgendwas"
[/autoit][autoit][/autoit][autoit]
;Global $aFile
;_FileReadToArray($sPath, $aFile)
;_ArrayDelete($aFile, 0)Dim $aFile[4] = ["hallo", "welt", "foo", "bar"]
[/autoit][autoit][/autoit][autoit]_shuffleUpAndDeal($aFile)
[/autoit][autoit][/autoit][autoit]Func _shuffleUpAndDeal(ByRef $aArray)
[/autoit][autoit][/autoit][autoit]
$j = UBound($aFile) -1 + Random(100,200,1)
For $i = 0 To $j
do
$a = Random(0, UBound($aFile)-1, 1)
$b = Random(0, UBound($aFile)-1, 1)
Until $a <> $b
_ArraySwap($aFile[$a], $aFile[$b])
Next
EndFunc_ArrayDisplay($aFile)
[/autoit]
Ich hatte Spassedit:
Nein, ernsthaft:Spoiler anzeigen
[autoit]; #FUNCTION# ====================================================================================================================
[/autoit] [autoit][/autoit] [autoit]
; 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
[/autoit] [autoit][/autoit] [autoit]; Bounds checking
[/autoit] [autoit][/autoit] [autoit]
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:
[/autoit] [autoit][/autoit] [autoit]
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:
[/autoit]
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 -
Vielen Dank, nur wie wende ich dieses Beispiel nun mit meinen 650 Zeilen an?
-
Ich hab oben noch eine ernsthaftere Funktion reineditiert
In meinem, nennen wir es mal Beispiel, findest du am Anfang ein paar auskommentierte Zeilen. Die du für das Einlesen der Datei in ein Array verwenden kannst.
-
Also er sagt mit jetzt dass er die Funktion _FileReadToArray() nicht finden kann.
Ich habe sie in meiner Array.au3 auch nicht gefunden. Ist das normal? -
[autoit]
#include <File.au3>
[/autoit]
Wenn du nicht weisst, in welchem include du eine Funktion findest, dann schau in der Hilfe zu der Funktion. Dort wirst du sie immer finden. -
Wenn du mal nicht weißt, welche Includes du brauchst, empfehle ich dir Organize Includes