Imports System
Imports System.Collections.Generic
Module UniqueHexColors
' Convert an integer (0–255) to a two-digit HEX string.
Function ToHex(value As Integer) As String
Return value.ToString("X2").ToLower()
End Function
' Generate N unique random HEX colors.
Function GenerateRandomUniqueHexColors(count As Integer) As String()
Dim seen As New HashSet(Of String)()
Dim colors(count - 1) As String
Dim rnd As New Random()
Dim generated As Integer = 0
While generated < count
Dim r As Integer = rnd.Next(0, 256)
Dim g As Integer = rnd.Next(0, 256)
Dim b As Integer = rnd.Next(0, 256)
Dim hex As String = "#" & ToHex(r) & ToHex(g) & ToHex(b)
If seen.Add(hex) Then
colors(generated) = hex
generated += 1
End If
End While
Return colors
End Function
Sub Main()
Dim n As Integer = 12
Dim colors = GenerateRandomUniqueHexColors(n)
Console.WriteLine("Generated HEX colors:")
For Each c In colors
Console.WriteLine(c)
Next
End Sub
End Module
'
' run:
'
' Generated HEX colors:
' #03e686
' #e9d60c
' #00cba7
' #6f926d
' #0a33b7
' #a4d930
' #48d4fe
' #fab3fb
' #1ba2d8
' #553216
' #d88f09
' #1eb30f
'