Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a random number wihout RND.
#13
One could also use GUIDs/UUIDs for seeds.

In Linux:
`cat /proc/sys/kernel/random/uuid` or `uuidgen`

In Windows with PowerShell installed:
`PowerShell -NoProfile [guid]::NewGuid().ToString()`

Both ways would require you to output to a file or use pipecom to capture the stdout.
You could also use the WinAPI to generate version 1 (sequential and based on MAC address) and version 4 (random) UUIDs.
The above terminal command options generate version 4 UUIDs, which are truly unique and don't reveal your MAC address.

You could also use the new HTTP options in QB64PE to do a simple GET request with the uuidtools REST API. It can generate versions 3 and 5 and create the UUIDs based on a hash of a provided string. UUIDs made this way are NOT random and can be created repeatedly. Can be handy to verify input against a stored UUID.

EDIT - Using the uuidtools REST API:
Code: (Select All)
Function UUIDVer3$ (mode As Integer, StringToHash As String)
    Dim As String UUID, URL, location
    'Dim As GUID GUID
    Dim As Long status
    location = "/api/generate/v3/namespace/"
    Select Case mode
        Case 1
            location = location + "ns:dns/name/"
        Case 2
            location = location + "ns:url/name/"
        Case 3
            location = location + "ns:oid/name/"
        Case 4
            location = location + "ns:x500/name/"
    End Select
    Dim As Long client: client = _OpenClient("HTTP:" + "https://www.uuidtools.com" + location + StringToHash)
    If client Then
        If _StatusCode(client) = 200 Then
            Dim As String buf, content
            While Not EOF(client)
                Get client, , buf
                content = content + buf
            Wend
            Close client
            UUID = UCase$(Mid$(_Trim$(content), 3, 36))
        End If
    End If
    'StringToUUID UUID, GUID
    'GUIDHash = UuidHash(GUID, status)
    UUIDVer3 = UUID
End Function

Function UUIDVer5$ (mode As Integer, StringToHash As String)
    Dim As String UUID, URL, location
    'Dim As GUID GUID
    Dim As Long status
    location = "/api/generate/v5/namespace/"
    Select Case mode
        Case 1
            location = location + "ns:dns/name/"
        Case 2
            location = location + "ns:url/name/"
        Case 3
            location = location + "ns:oid/name/"
        Case 4
            location = location + "ns:x500/name/"
    End Select
    Dim As Long client: client = _OpenClient("HTTP:" + "https://www.uuidtools.com" + location + StringToHash)
    If client Then
        If _StatusCode(client) = 200 Then
            Dim As String buf, content
            While Not EOF(client)
                Get client, , buf
                content = content + buf
            Wend
            Close client
            UUID = UCase$(Mid$(_Trim$(content), 3, 36))
        End If
    End If
    'StringToUUID UUID, GUID
    'GUIDHash = UuidHash(GUID, status)
    UUIDVer5 = UUID
End Function
   
Tread on those who tread on you

Reply


Messages In This Thread
Getting a random number wihout RND. - by Dav - 09-30-2023, 11:01 PM
RE: Getting a random number wihout RND. - by Dav - 09-30-2023, 11:06 PM
RE: Getting a random number wihout RND. - by Dav - 09-30-2023, 11:27 PM
RE: Getting a random number wihout RND. - by Dav - 10-01-2023, 01:45 AM
RE: Getting a random number wihout RND. - by SpriggsySpriggs - 10-02-2023, 05:14 PM
RE: Getting a random number wihout RND. - by Pete - 07-17-2024, 07:00 PM
RE: Getting a random number wihout RND. - by Pete - 07-17-2024, 07:42 PM
RE: Getting a random number wihout RND. - by Pete - 07-17-2024, 09:00 PM
RE: Getting a random number wihout RND. - by Pete - 07-17-2024, 10:08 PM



Users browsing this thread: 4 Guest(s)