[Gambas-user] Is there in Gambas a UUID implementation?

vuott at tutanota.com vuott at tutanota.com
Fri May 12 13:20:33 CEST 2023


« ...to use Extern... »

Maybe....

[code]
Library "libc:6"

' void srand (unsigned int __seed)
' Seed the random number generator with the given number.
Private Extern srand(__seed As Integer)

' int rand (void)
' Return a random integer between 0 and RAND_MAX inclusive.
Private Extern rand_C() As Integer Exec "rand"

Public Sub Main()

' "01/01/1970" is Unix Time Stamp - Epoch:
  srand(DateDiff("01/01/1970", Now, gb.Second))
  
  Print Hex(Rand32(), 8); "-"; Hex(Rand32() And &ffff&, 4); "-"; Hex((Rand32() And &0fff) Or &4000, 4); "-"; Hex((Rand32() And &3fff) + &8000, 4); "-"; Hex(Rand32() And &ffff&, 4); Hex(Rand32(), 8)
    
End 

Private Function Rand32() As Integer
    
  Return (Lsl(rand_C() And &03, 30)) Or (Lsl(rand_C() And &7fff, 15)) Or (rand_C() And &7fff)
    
End[/code]




12 mag 2023, 12:10 da mbelmonte at belmotek.net:

> El 11/5/23 a las 23:24, Martín escribió:
>
>> Is there in Gambas a UUID implementation?
>>
>
> Thanks for the answers, both of them  using uuidgen tool although shell in gambas, it works but is more efficient use this:
>
> Private Function UUID() As String
>
>   Return RTrim(File.Load("/proc/sys/kernel/random/uuid"))
>
> End
>
> Anyway if somebody know how to use Extern with the libuuid it could be even more efficient (I guest).
>
> Best regards.
>
> Martin.
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230512/4a98e57a/attachment.htm>


More information about the User mailing list