cypher175 Posted March 9, 2009 Share Posted March 9, 2009 i know how to generate a random number but how can i Generate a random number in this format 000,001,002,003 Ect..?? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 9, 2009 Moderators Share Posted March 9, 2009 cypher175,Look at StringFormat in the Help file. In your case you would need StringFormat("%03i", $Random_Number)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...
GerrOrneq Posted March 9, 2009 Share Posted March 9, 2009 i know how to generate a random number but how can i Generate a random number in this format 000,001,002,003 Ect..??Hi, While I was away typing in my 2 cents worth and having a bite to eat Melba23 answered, and I too learned something new from his reply.I was not aware of the built-in padding ability, I was doing it the 'old' way.It just goes to show that you can teach an old dog new tricks. The moral being: Read The Help File As I have already typed the example here it is anywayCODELocal $ILocal $PLLocal $PR$I = Int(Random(0, 100))$PL = StringRight("00000" & $I, 5)$PR = StringLeft($I & "00000", 5)MsgBox(0, "Random number", "The random number is - " & @TAB & $I & @CRLF & @CRLF & "The Left padded number is - " & @TAB & $PL & @CRLF & "The right padded number is - " & @TAB & $PR)This method allows you to pad either Left or Right.Good Luck. Quote of the week:"BASIC programmers never die, they GOSUB and don't RETURN." -- UnknownWisdom of the ages: I'd be unstoppable... if not for law enforcement and physics. Marriage, the number 1 cause of divorce. Don't steal... the government hates competition. Irish Government Motto: We’ve got what it takes to take what you’ve got. Birthdays are good for you. Statistics show that the people who have the most live the longest. Failure is not an option. It comes bundled with your Microsoft product.-- Ferenc Mantfeld If you learn from your mistakes, then why ain't I a genius?! -- Anonymous Remember, live every day as if it was your last day! one day you will be right. How is it one careless match can start a forest fire, but it takes a whole box to start a campfire? Sure my system is secure, it just locked up again. I haven't lost my mind; I have a tape back-up somewhere. ~Author Unknown Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 9, 2009 Share Posted March 9, 2009 I think Melba23 was talking about doing that for each of the four parts. The problem with the original number format is that it can contain integer numbers too large to be represented as a single 32-bit integer, which is all Random() can return. So you have to assemble the number: For $n = 1 To 10 $sNum = StringFormat("%03i,%03i,%03i,%03i", Random(0, 999, 1), Random(0, 999, 1), _ Random(0, 999, 1), Random(0, 999, 1)) ConsoleWrite("$sNum = " & $sNum & @LF) Next Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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