Sign in to follow this  
Followers 0
cypher175

Generating a random number in this format 000,001,002 Ect..?

4 posts in this topic

i know how to generate a random number but how can i Generate a random number in this format 000,001,002,003 Ect..??

Share this post


Link to post
Share on other sites



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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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. :P

The moral being: Read The Help File :unsure:

As I have already typed the example here it is anyway

CODE

Local $I

Local $PL

Local $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

Share this post


Link to post
Share on other sites

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

:P


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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0