Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 05-17-2003, 06:08 AM
desertoug desertoug is offline
Junior Member
 
Join Date: May 2003
Posts: 2
Default Random string

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.
Reply With Quote
  #2  
Old 05-17-2003, 06:14 AM
Stoney Stoney is offline
Member
 
Join Date: Dec 2002
Posts: 85
Default RE: Random string

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
Reply With Quote
  #3  
Old 08-05-2019, 07:17 AM
myicq myicq is offline
Junior Member
 
Join Date: Apr 2017
Posts: 1
Default

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;
result:


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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 11:25 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.