FMS Posted April 29, 2018 Posted April 29, 2018 (edited) Hello, I'm trying to randomly change some cells in a array on a given percentage. at this point I 've a array whit all 0's and want to change some cells to 1. I'm not shure how to do this in a good coding sort of way. Also maybe there is a build in function whish I'm not aware of. Does somebody know how I can do this in a easy way? I was trying to get the total count of cells and get the percentage of it. And was stuck when i wanna change the cell. please advice, thanks in advanced for your help. #include <Array.au3> Global $percentage = 0.2 Global $aArray[Random(10,30,1)][Random(10,30,1)] For $x = 0 To UBound($aArray,1) - 1 For $y = 0 To UBound($aArray,2) - 1 $aArray[$x][$y] = 0 Next Next _ArrayDisplay($aArray) randomize() _ArrayDisplay($aArray) Func randomize() Local $total_to_change = ((UBound($aArray,1) * UBound($aArray,2)) / 100) * $percentage ConsoleWrite( "$total_to_change = " & $total_to_change & @LF ) ConsoleWrite( "total in array = " & (UBound($aArray,1) * UBound($aArray,2)) & @LF ) EndFunc Edited April 29, 2018 by FMS as finishing touch god created the dutch
Moderators Melba23 Posted April 29, 2018 Moderators Posted April 29, 2018 FMS, Use Random to set the array elements to 1 or 0 as you create the array: #include <Array.au3> Global $percentage = 0.2 Global $aArray[Random(1, 10, 1)][Random(1, 10, 1)] _ArrayDisplay($aArray) For $x = 0 To UBound($aArray, 1) - 1 For $y = 0 To UBound($aArray, 2) - 1 $aArray[$x][$y] = ((Random(0, 1) < $percentage) ? (1) : (0)) Next Next _ArrayDisplay($aArray) 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
FMS Posted April 29, 2018 Author Posted April 29, 2018 who thanks for this. This show's that i was realy thinking to dificult once again totaly what i was aming for +1 for @Melba23 as finishing touch god created the dutch
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