![]() |
#1
|
|||
|
|||
![]()
I'm working on a program that should change the MAC address with a random one.
I've generated random numbers, but I would like to generate random strings. I've tried with an array from which I should get random indexes, but it doesn't work. Or maybe there is a way to generate random Hex value. |
#2
|
|||
|
|||
![]()
function Randomstring(strLen: Integer): string;
var str: string; begin Randomize; str := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ'; Result := ''; repeat Result := Result + str[Random(Length(str)) + 1]; until (Length(Result) = strLen) end; procedure TForm1.Button1Click(Sender: TObject); begin //generate a string with 10 chars showmessage( Randomstring(10)); end; Stoney |
#3
|
|||
|
|||
![]()
Bringing up this old thread... Just wanted to state that if you put randomize() into the function, and call that function in a loop, you will end up with a sequence of identical "random" values.
Like this: Code:
for i:= 1 to 10 do begin getRandomValue(5); end; abc123 abc123 abc123 abc123 kkk998 kkk998 PCs use clock to randomize, so if you call the function multiple times each msec, it's same value. |
![]() |
Thread Tools | |
Display Modes | |
|
|