Jump to content
Sign in to follow this  
7121

removing duplicates in a string

Recommended Posts

7121

basically i have this

$Ran = Random(1, 9 )

Which btw, does anyone know how to make random like a huge number, without FLOAT??? o_0

okay, after that,

$Ran = $Ran*123456789
$Ran = Int ($Ran)

easiest way i know to make a huge RANDOM number as an integer =/

Now the problem is i don't want duplicates ^_^.

example:

11, 2222, 33333333, 444,

basically i only want 1712938125, each number is different on every next digit. I think it's really easy but somehow i'm not figuring it out and i go with manual of StringReplace... like LOTS of them, about 20 of them, hoping the duplicate won't show up.

Share this post


Link to post
Share on other sites
Melba23

7121,

Random will deal with numbers up to 2^31 (that is up to 2,147,483,647) - I think that counts as 'huge'. Setting the 'Flag' parameter will return integers - so that is the first question dealt with!

Now to the 'duplicate' problem - as you do not want successive integers to be the same, we are already outside any real defintion of "random", so why not just amend the numbers so they no longer match? Although I feel we should make at least a token effort by increasing or decreasing them at random! :-):

;  Get large integer
$sInt = String(Random(1000000, 10000000, 1))
; Split into elements
$aInt = StringSplit($sInt, "")
; Increase/decrease elements randomly if they match preceding element
For $i = 1 To $aInt[0] - 1
    If $aInt[$i + 1] = $aInt[$i] Then
        $iUpDown = Random(0, 1)
        If $iUpDown > .5 Then
            $aInt[$i + 1] += 1
            If $aInt[$i + 1] = 10 Then $aInt[$i + 1] = 0
        Else
            $aInt[$i + 1] -= 1
            If $aInt[$i + 1] = -1 Then $aInt[$i + 1] = 9
        EndIf
    EndIf
Next
; Recreate number
$sInt = ""
For $i = 1 To $aInt[0]
    $sInt &= $aInt[$i]
Next
$iInt = Int(Number($sInt))
; Display it
ConsoleWrite($iInt & @CRLF)

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
TheSaint

basically i have this

Now the problem is i don't want duplicates ^_^ .

example:

11, 2222, 33333333, 444,

basically i only want 1712938125, each number is different on every next digit. I think it's really easy but somehow i'm not figuring it out and i go with manual of StringReplace... like LOTS of them, about 20 of them, hoping the duplicate won't show up.

I'd go with StringMid and count your way through the number, and keep incrementing so that next number doesn't match last, so that

11, 2222, 33333333, 444,

would become

12, 3232, 34343434, 545,

if you just incremented by 1 each time.

If you vary the increment each time, then you would get a less uniform number.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
jchd

Now the problem is i don't want duplicates ^_^.

example:

11, 2222, 33333333, 444,

basically i only want 1712938125, each number is different on every next digit. I think it's really easy but somehow i'm not figuring it out and i go with manual of StringReplace... like LOTS of them, about 20 of them, hoping the duplicate won't show up.

There are plenty of high quality proven random number generators floating around, just google. BTW, discarding 33333 is definitely not a good idea. 33333 is as random as 57404583 can be. It "just" happen to have a decimal expression that makes it easy to spot. Express your numbers in hex and you'll find a completely different set of "not looking random" numbers. Then try octal or binary or ... Even duplicates in 2^32 are "normal" (I won't go into a mathematical discussion about what that means).

Duplicates might be unsuited to your precise application, but they are nothing else than "normal". Not finding any would be a _big_ security breach! Think about it: roll a dice and apply your paradigm: if you got 3 then you must get something else! Roll the dice 5 times and --if dups are banned-- I for one that can predict which shall be the next number. This is clearly getting more and more predictable (the contrary to random) as the number of values already appeared increase and tend towards the number of possibilities.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Xenobiologist

ConsoleWrite(_randomNr(10) & @CRLF)

Func _randomNr($length = 1)
    Local $nr = Random(0, 9, 1), $tmp = ''
    While StringLen($nr) < $length
        $tmp = Random(0, 9, 1)
        If $tmp <> StringRight($nr, 1) Then $nr &= $tmp
    WEnd
    Return $nr
EndFunc  ;==>_randomNr

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
7121

thank you very much guys... even though i'm still a little confused ^_^ but i'll figure it out

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  

×