• ** There has been a recent site upgrade. Please clear your browser cache to avoid issues. **
  • New forum feature - post voting and best solution

    Check out this thread for the details: https://www.access-programmers.co.uk/forums/threads/new-forum-feature-post-voting-and-best-answer.314134/

    This new feature looks great to me! :)

  • We now have 3 forum themes

    Go for the default (light) theme, Shades of Grey or Shades of Blue. I just added the Blue one.

    The thread about it is here: https://www.access-programmers.co.uk/forums/threads/new-forum-theme-shades-of-blue.314136/

Scramble Text (1 Viewer)

Status
Not open for further replies.

Guus2005

AWF VIP
Local time
Today, 20:17
Joined
Jun 26, 2007
Messages
2,584
This function replaces every character with a random similar character.
I use this function to anonymize data in tables.

Almost but not quite entirely unlike the post made by Micron a few months ago.

Share & Enjoy!

Code:
Option Compare Binary
Option Explicit

Public Function ScrambleIt(strString As String) As String
    'Replace matching case and numbers
    'ScrambleIt("Kerkstraat 45, 8194AZ, Baarn")
    '           "Gibmfwptyi 50, 6491YQ, Jdmfz"
    Const cUAlpha As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    Const cLAlpha As String = "abcdefghijklmnopqrstuvwxyz"
    Const cNum As String = "0123456789"
    Dim lngLoop As Long
    Dim strNewChar As String
    Dim strThisChar As String

    Randomize
    
    For lngLoop = 1 To Len(strString)
        strThisChar = Mid$(strString, lngLoop, 1)
        Select Case strThisChar
            Case "a" To "z"
                strNewChar = Mid$(cLAlpha, Int(Rnd * Len(cLAlpha)) + 1, 1)
                If Asc(strThisChar) > Asc("z") Then strNewChar = Asc("a") + (Asc(strThisChar) - Asc("a") - 1)
            Case "A" To "Z"
                strNewChar = Mid$(cUAlpha, Int(Rnd * Len(cUAlpha)) + 1, 1)
                If Asc(strThisChar) > Asc("Z") Then strNewChar = Asc("A") + (Asc(strThisChar) - Asc("A") - 1)
            Case "0" To "9"
                strNewChar = Mid$(cNum, Int(Rnd * Len(cNum)) + 1, 1)
                If Asc(strThisChar) > Asc("9") Then strNewChar = Asc("0") + (Asc(strThisChar) - Asc("0") - 1)
            Case Else
                strNewChar = strThisChar
        End Select
        ScrambleIt = ScrambleIt & strNewChar
    Next
End Function
 
Last edited:

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 05:17
Joined
Jan 20, 2009
Messages
12,078

Micron

AWF VIP
Local time
Today, 14:17
Joined
Oct 20, 2018
Messages
3,469
It's pseudo random because each number seeds the generator for the next number, yes? If this were about a system picking winning lottery numbers, then I'd agree that rnd by itself is insufficient. However, there is no way (that I know of) that you're going to repeat the exact sequence when the function is run again, even if it were to start with the same number. If you say different, how about if I scramble some data and you unscramble it?
 

Micron

AWF VIP
Local time
Today, 14:17
Joined
Oct 20, 2018
Messages
3,469
Due to the pseudo randomness (which could be easily solved) and the fact that i missed an earlier post which Colin pointed out, i think this post could be deleted since it adds nothing much :(
If I understand that statement, you're suggesting that the randomness factor could be improved by implementing the suggestion(s) at the link you posted. I have some requests/suggestions on the back burner that I have to review and I don't see why that one can't be added. At the very least, it ought to alleviate any such concerns, although I doubt that the results can be reversed as it stands.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:17
Joined
May 21, 2018
Messages
3,489
If this were about a system picking winning lottery numbers, then I'd agree that rnd by itself is insufficient. However, there is no way (that I know of) that you're going to repeat the exact sequence when the function is run again, even if it were to start with the same number.
No you are wrong. It is not a bug, but purposely designed this way. If you do an experiment you want to get a unique set of numbers, but you would like to be able to run it again with the same unique set of numbers. So if you do not randomize or modify the see and close the db, then rerun it you will get that same unique sequence of numbers. I have demonstrated this on numerous threads. So if you are not uniquely seeding then you need to randomize. The term pseudo random has nothing to do with the seed, but with the algorithm. AFAIK no one has developed a truly random number generator via a pure code algorithm, they are really really good but not truly random.
https://www.random.org/randomness/
There are systems to pull truly random numbers.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:17
Joined
May 21, 2018
Messages
3,489
Here is the demo showing randomize and not randomize. If you open the form you will see I list the order of the random IDs returned for the first three requeries. The list on the left employs does not use randomize, the one on the right does.
 

Attachments

  • CompareRandomize.accdb
    572 KB · Views: 29
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom