Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
500 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


Fast ID generationGo to Andrey Sorokin's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
Random strings generation
Product:
Delphi all versions
Category:
Algorithm
Skill Level:
Scoring:
Last Update:
06/01/2000
Search Keys:
delphi delphi3000 article borland vcl code-snippet random string ID generate password registration code
Times Scored:
7
Visits:
6344
Uploader: Andrey Sorokin
Company: AlkorSoft
Reference: AnSo Home page
 
Question/Problem/Abstract:
How to generate random ID
Answer:



Sometimes I have to send registration codes for my applications thru fax or postoffice. In that case it is essential to prevent misundestanding of any characted in code.

I use following code for generation passwords with well distinguishable characters (furthermore it works very fast ;) )

function RandomStr (ALen : integer) : string;
// ALen - desired length of password
const Tbl : array [0 .. $1F] of char = (
  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
  'C', 'D', 'E', 'F', 'G', 'H', 'K', 'M', 'N', 'P', 'Q', 'R',
  'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
var i, n, k, x, j : integer;
begin
  SetString (Result, nil, ALen);
  n := ALen * 5; // bits in random number
  j := 1;
  while n > 0 do begin
    if n > 30 then k := 30 // work with 32-bits numbers
     else k := n;
    x := Random (1 shl k - 1);
    for i := 1 to k div 5 do begin
      Result [j] := Tbl [x and $1F];
      inc (j);
      x := x ShR 5;
     end;
    dec (n, k)
   end;
end; { of function RandomStr
--------------------------------------------------------------}






Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
D. Souchard
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)