Read Posted March 5, 2011 Share Posted March 5, 2011 How to make random combinations script Ex. test.txt is number combinations 01 02 03 01 02 04 01 02 05 test.bin coming random combinations 01 02 05 01 02 03 01 02 04 $sData = FileRead(@ScriptDir & "\test.txt") $random = // random code here!!! How? $hFile = FileOpen(@ScriptDir & "\test.bin", 18) FileWrite($hFile, $random) FileClose($hFile) Eng bad Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 5, 2011 Moderators Share Posted March 5, 2011 Read,How to make random combinationsDid you look to see if Random appeared in the Help file? Probably not or you would have found it. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Read Posted March 5, 2011 Author Share Posted March 5, 2011 test.bin come always "NULLNULLČ»¢Q9@" -something is very wrong. maybe help? Link to comment Share on other sites More sharing options...
guinness Posted March 5, 2011 Share Posted March 5, 2011 (edited) That could be correct, but without any code it can be a little difficult to diagnose the problem Edit: Check the flags for FileOpen()Global $sRandom = Random(0, 100) Global $hFile = FileOpen(@ScriptDir & "\Test.bin", 2) FileWrite($hFile, $sRandom) FileClose($hFile) Edited March 5, 2011 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Read Posted March 5, 2011 Author Share Posted March 5, 2011 (edited) What is it > 59.7735021729022 ? test.bin must coming random combinations - take test.txt comb. and make random in test.bin one example of 100 - not work $sData = FileRead(@ScriptDir & "\test.txt") $random1 = Random($sData,0) $hFile = FileOpen(@ScriptDir & "\test.bin", 18) FileWrite($hFile, $random1) FileClose($hFile) Edited March 5, 2011 by Read Link to comment Share on other sites More sharing options...
Bowmore Posted March 5, 2011 Share Posted March 5, 2011 (edited) If I have understood your first post correctly, then I think this may be what you are looking for. #include <file.au3> local $aData,$MaxRow,$rmd,$temp, _FileReadToArray(@ScriptDir & "\test.txt", $aData) $MaxRow = UBound($aData) - 1 For $i = 1 To $MaxRow $rnd = Random(1, $MaxRow, 1) $temp = $aData[$i] $aData[$i] = $aData[$rnd] $aData[$rnd] = $temp Next $hFile = FileOpen(@ScriptDir & "\test.bin", 18) For $i = 1 To $MaxRow FileWrite($hFile, $random1) Next FileClose($hFile) Edit: fixed bug in script Edited March 5, 2011 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
Read Posted March 5, 2011 Author Share Posted March 5, 2011 Bowmore!Edit only: #include <arrsy.au3> >> #include <array.au3>Error:Array.au3 don't have _FileReadToArray but File.au3 is it - both not work Link to comment Share on other sites More sharing options...
Bowmore Posted March 5, 2011 Share Posted March 5, 2011 Script in previous post has now been fixed. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
somdcomputerguy Posted March 5, 2011 Share Posted March 5, 2011 (edited) What is it > 59.7735021729022 ? The Random() function has flags too. Change $random1 = Random($sData,0) to $random1 = Random($sData,1) <strike>or</strike> and, read thru the Help file some more. Edited March 5, 2011 by somdcomputerguy - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
MvGulik Posted March 6, 2011 Share Posted March 6, 2011 Random ( [Min [, Max [, Flag]]] ) Parameters Min [optional] The smallest number to be generated. The default is 0. Max [optional] The largest number to be generated. The default is 1. Flag [optional] If this is set to 1 then an integer result will be returned. Default is a floating point number. "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 ... Link to comment Share on other sites More sharing options...
Read Posted March 6, 2011 Author Share Posted March 6, 2011 Not work.Error:Script in previous post has now been fixed. Link to comment Share on other sites More sharing options...
Bowmore Posted March 6, 2011 Share Posted March 6, 2011 You should be capable of fixing that yourself. Just remove the stray comma at the end of the line as indicated by the error message. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
Read Posted March 6, 2011 Author Share Posted March 6, 2011 Can't Something is wrong here or no: FileWrite($hFile, $random1)??? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 6, 2011 Moderators Share Posted March 6, 2011 (edited) $random1 looks to be a code mistake. Replace it with: $aData[$i] Edit: After looking at that code, I don't see you still getting the results you want. There was no exception made for carriage return/Line feeds. And it's still reading an "ansi" text file, then writing it to a binary file... not sure why we'd do that. Edited March 6, 2011 by SmOke_N missed code tag Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Read Posted March 6, 2011 Author Share Posted March 6, 2011 Yes, not work. What would be a working code? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 6, 2011 Moderators Share Posted March 6, 2011 (edited) Yes, not work. What would be a working code? The working solution could happen much faster if you took the time and did some tutorials. You are showing us no desire to either read the help file, comprehend it, or both. http://www.autoitscript.com/wiki/FAQ#Where_can_I_learn_AutoIt.3F_Are_there_any_tutorials.3F Keep in mind, anyone that helps you here is because they want to. There are no have to's. I assume this is what you're after. expandcollapse popup#region Example only data Global $gs_filefrom = @ScriptDir & "\test.txt" Global $gs_fileto = @ScriptDir & "\test.bin" If Not _my_FileToRandomLines($gs_filefrom, $gs_fileto) Then Switch @error Case 1 MsgBox(16 + 262144, "Error", "Error opening " & $gs_filefrom) Case 2 MsgBox(16 + 262144, "Error", "Empty file " & $gs_fileto) Case 3 MsgBox(16 + 262144, "Error", "Error opening " & $gs_fileto) EndSwitch Exit EndIf #region Example only data ; Param 1: The file to read from ; Param 2: The file to write to ; Param 3: The read flag ( default is 0 for reading standard text file ) ; Param 3: The write flag ( default is 2 for erasing old content and creating a new standard text file ) Func _my_FileToRandomLines($s_filein, $s_fileout, $i_readflag = 0, $i_writeflag = 2) If $i_readflag = -1 Or $i_readflag = Default Then $i_readflag = 0 If $i_writeflag = -1 Or $i_writeflag = Default Then $i_writeflag = 2 ; open with reader flag mode Local $h_open = FileOpen($s_filein, $i_readflag) If $h_open = -1 Then Return SetError(1, 0, 0) Local $s_fread = FileRead($h_open) FileClose($h_open) If $s_fread = "" Then Return SetError(2, 0, 0) ; open write to file $h_open = FileOpen($s_fileout, $i_writeflag) If $h_open = -1 Then Return SetError(3, 0, 0) ; split file lines Local $a_lines = StringSplit(StringStripCR($s_fread), @LF) ; shuffle lines, start at index 1, index 0 is only count Local $a_writelines = _ArrayShuffle($a_lines, 1) For $iline = 1 To $a_writelines[0] FileWriteLine($h_open, $a_writelines[$iline]) Next FileClose($h_open) Return 1 EndFunc Func _ArrayShuffle($a_arr, $i_lb = 0) Local $i_ub = UBound($a_arr) - 1 Local $v_tmp, $i_rndm For $irow = $i_lb To $i_ub $v_tmp = $a_arr[$irow] $i_rndm = Random($i_lb, $i_ub, 1) $a_arr[$irow] = $a_arr[$i_rndm] $a_arr[$i_rndm] = $v_tmp Next Return $a_arr EndFunc Edited March 6, 2011 by SmOke_N brainfart Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Read Posted March 6, 2011 Author Share Posted March 6, 2011 works very well, thanks SmOke_N! Thanks all Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now