I.T. Discussion Community!
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

September Edition
Subscribe now! It's Free!
Enter your email:

   ► MB LobbyPascal and Delphi Coding BoardDelphi Object PASCAL Topic   Print This     

Random function

Random function in Delphi Object PASCAL topic (part of our Pascal and Delphi Coding group).

Quick Search: function   Random function  
Angel
 (Inactive)
England
Not so much a question as a query (Is there a difference? Geek Alert! ). Being a trifle bored in the office the other week, I decided to write a simple program to generate some (losing! Banging Head On Wall ) lottery numbers. Having run the program a few times since then, I have noticed that the system has a habit of generating at least two numbers that are together numerically almost every time Think! . I will admit that this is plausible given that there are only 49 numbers and six unique numbers are required but to do it almost every time??? I was wondering if anybody knew how the Random function in Delphi works for future refernce in slightly more important software I may have to write.

Randomize;
repeat
X := Random(49);
until X <> 0;

As each new number is generated, code is tagged onto the Until line to prevent the system returning a number already generated.

eg
until (X <> 0) and (IntToStr(X) <> Label1.Caption)
 Posted 16 years ago (Thread Starter)
Comment Quote
About Angel -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8910, 1 replies
Thread Started 1/13/2003 7:39:00 AM
View Counter=2504
Last Reply Posted 1/16/2003 7:04:00 AM)
Location=England  
Joined=18 years ago   MB Posts=199  
Most Recent Post
NevilleRichards
 (Inactive)
UK
After the first number, the chance of the next on not being "near" it is 46/48.

After two numbers, chance of another not near either is 43/47.

So the five steps after the first yield probability of

46.43.40.37.34/(48.47.46.45.44)

= 0.48

So slightly less than evens (approximately) that you won't get two numbers next to each other.

Not perfect probability, but I suspect a reasonable approximation. Similar to getting all differnet birthdays in a group of people. More than 23, and you are more likely to get a shared birthday than not.

Neville
 Posted 16 years ago
Comment Quote
About NevilleRichards -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8938 (Level 1.1)  Reply to 8910
Thread Started 1/16/2003 7:04:00 AM
View Counter=2
Location=UK  
Joined=18 years ago   MB Posts=41  

Revive Thread!

Add a comment to revive this old thread and make this archived thread more useful.

Write a Comment...
Full Editor
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1173A1
Enter key:
Icon: A Post    Thread    Idea    Important!    Cool    Sad    No    Yes    Includes a Link...   
Thread #8910 Counter
2504
Since 4/2/2008

Follow PrestwoodBoards on: 


©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech