PCI Posted May 19, 2015 Posted May 19, 2015 Hi everyone I've read all yesterday forums , i think it's me , but i could not find a clue for this :I need to generate large numbers and output into csv format or excel format- Range between 3000000 and 9000000 - Need 5000000 numbers- Numbers should not be in series ( Mixed and Random )- I would prefere to have a check digits at the endAnyone could help please ? Thank you
Moderators Melba23 Posted May 19, 2015 Moderators Posted May 19, 2015 PCI,Random will produce the numbers for you (although 5000000 will take a little time) - and formatting the results as .csv should not prove difficult. But what do you mean by check digits?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
PCI Posted May 19, 2015 Author Posted May 19, 2015 @Melba23 Thank you so much for your reply !I need to produce set of 5 millions numbers the numbers , i need to make check digits at the end to validate the numbers with an algorithm like mod10 or luhrn .I prefer to validate 8 digits Please help Thank you
Moderators Melba23 Posted May 19, 2015 Moderators Posted May 19, 2015 (edited) PCI,Do you mean something like this:expandcollapse popup#include <FileConstants.au3> #include <MsgBoxConstants.au3> ; Create file $sFile = "Test.csv" $hFile = FileOpen($sFile, $FO_OVERWRITE) $sLine = "" ; Produce numbers (100 here as an example) For $i = 1 To 100 ; Create a random number $sNumber = String(3000000 + Random(0, 6000000, 1)) ; Calculate a check digit $iCheckSum = 0 For $j = 1 To 7 $iCheckSum += StringMid($sNumber, $j, 1) Next $iCheckDigit = Mod($iChecksum, 10) ; Add the number and check digit to the line $sLine &= $sNumber & "-" & $iCheckDigit & "," ; Write every a line to the file every 5 numbers If Mod($i, 5) = 0 Then $sLine = StringTrimRight($sLine, 1) FileWrite($hFile, $sLine & @CRLF) $sLine = "" EndIf Next ; Close the file FileClose($hFile) ; And here is the result $sData = FileRead($sFile) MsgBox($MB_SYSTEMMODAL, "Random", $sData)Just out of interest, why do you need so many random numbers?M23Edit:And here is the Luhn version (now I know what it is!):#include <FileConstants.au3> #include <MsgBoxConstants.au3> $sFile = "Test.csv" $hFile = FileOpen($sFile, $FO_OVERWRITE) $sLine = "" For $i = 1 To 100 $sNumber = String(3000000 + Random(0, 6000000, 1)) $iCheckSum = 0 For $j = 1 To 7 $iCheckSum += StringMid($sNumber, $j, 1) Next $iCheckSum *= 9 $sCheckDigit = StringRight(String($iCheckSum), 1) $sLine &= $sNumber & $sCheckDigit & "," If Mod($i, 5) = 0 Then $sLine = StringTrimRight($sLine, 1) FileWrite($hFile, $sLine & @CRLF) $sLine = "" EndIf Next FileClose($hFile) $sData = FileRead($sFile) MsgBox($MB_SYSTEMMODAL, "Random", $sData) Edited May 19, 2015 by Melba23 PCI 1 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
PCI Posted May 19, 2015 Author Posted May 19, 2015 Thank you so much @Melba23 you ROCK !I'm really suprized how clean and easy to readI'm trying to distibute a unique code to random friends to access a web pageHowever i could not generate the results with these requirements - Fixed length if possible - Range from 1000000(1M) to 40000000(40M) - Mod10 check - Could i add carriage return to the output so they are only 1 set per ligne ? Thank you for making me learn , this i will make a gui with prompt to enter low range and hi range and select mod10 with check then click on output Great Forum / Great work / Genius Autoit
PCI Posted May 19, 2015 Author Posted May 19, 2015 Hi Melba23 ,Attached results that i have and edited scriptIf you see the results 10 generated number are not Mod10Please advise Thank you Number_Generator.au3 Test_mod10.csv
Moderators Melba23 Posted May 19, 2015 Moderators Posted May 19, 2015 PCI,Of course the numbers are not Mod 10 - you did not ask for them to be so. The code produces a Mod 10 checksum and adds it to the end of the random value - as this checksum will vary between 0 and 9, the final digit will also vary between those values.M23 PCI 1 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
PCI Posted May 19, 2015 Author Posted May 19, 2015 Thank you You are very helpful .I will try and add mod10 calculationI think it will be very hard for a newbie like me. :-)Any suggestions where to start please ?Regards
czardas Posted May 20, 2015 Posted May 20, 2015 (edited) Melba something looks wrong with your Luhn algorithm code. Here's my version. BTW your _ArrayDisplay range feature was very useful testing my code. PCI - The numbers you want to generate seem rather a lot. The method I use below generates Luhn numbers of 8 digits. Using _ArrayShuffle to create larger numbers is not a simple procedure. The reason is that arrays have a maximum limit of approx 16000000 elements. Only some clever work-around will allow you to exceed this range limit: assuming the numbers must be unique, as random as possible (within the range) and appear in any order. I have suspicions that you don't actually need all these numbers, but hopefully the code below will help. If there's something you don't understand then ask.expandcollapse popup#include <Array.au3> ; Maximum valid 8 digits Luhn Number = 99999997 ; Generate numbers from 1000000 to 9999999 Local $iMin = 1000000 Local $iMax = 9999999 Local $iBound = $iMax - $iMin +1 Local $aArray[$iBound] For $i = 0 To $iBound -1 $aArray[$i] = $iMin + $i Next _ArrayShuffle($aArray) ; Shuffle the numbers Local $iIterations = 1000 ; Suppose we only need 1000 random 8 digit Luhn numbers (for quick demonstration purposes) ReDim $aArray[$iIterations] ; Delete most of the array ; Aquire the last digit: needed to convert each 7 digit number to a valid 8 digit Luhn number For $i = 0 To $iIterations -1 $aArray[$i] &= GenerateLastLuhnDigit($aArray[$i]) Next _ArrayDisplay($aArray) Func GenerateLastLuhnDigit($vNumber) Local $iSum = 0, $sCurrDigit For $i = StringLen($vNumber) To 1 Step -2 ; Every second number from the right will be doubled. $sCurrDigit = StringMid($vNumber, $i, 1) ; Read each digit to be doubled starting from the right. $sCurrDigit *= 2 ; Multiply by 2. If $sCurrDigit > 9 Then $sCurrDigit = StringLeft($sCurrDigit, 1) + StringRight($sCurrDigit, 1) ; Make sure $sCurrDigit is not greater than 9. $iSum += $sCurrDigit + StringMid($vNumber, $i -1, 1) ; Also add the odd step value (not multiplied by 2) Next $iSum *= 9 ; Multiply the result by 9. Return Mod($iSum, 10) ; This digit can be appended to $vNumber to create a valid Luhn number. EndFunc Edited May 20, 2015 by czardas spelling operator64 ArrayWorkshop
PCI Posted May 20, 2015 Author Posted May 20, 2015 Hi czardas You guys are Genius !!!I'm testing as we speak , i'm trying to make a GUI to Input low range and High Range in this GUI also any possibility to have it output to a text file ?Thank you so much
czardas Posted May 20, 2015 Posted May 20, 2015 (edited) No problem, I guess you might just want to use the function GenerateLastLuhnDigit() to generate the final digit. It should work on any number size, but very large numbers must be passed as strings. The rest of my code is really intended to give you some ideas to play around with. Good luck. Edited May 20, 2015 by czardas operator64 ArrayWorkshop
PCI Posted May 20, 2015 Author Posted May 20, 2015 Cool worked just fine Very happy guys Thank youHowever , i have limitations to the output due to the maximum row 65524 , any thing i could do to output this as text file ?Thank you for the help God bless you
czardas Posted May 20, 2015 Posted May 20, 2015 (edited) _FileWriteFromArray() will do the job you need.By the way I never thought about whether you wanted numbers to include leading zeros. The lowest first digit is 1 in the numbers I am generating in the code above. Edited May 20, 2015 by czardas operator64 ArrayWorkshop
czardas Posted May 20, 2015 Posted May 20, 2015 (edited) You can also change the iterations to a maximum of 9000000 (any higher and the code will give you an error), but I don't know how long it will take to generate all the numbers. Probably not too long - you can try it if you want. However you will not be able to display all of the array - only parts of it. Write to file as you yourself suggested. Edited May 20, 2015 by czardas operator64 ArrayWorkshop
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