Random Number

madm
Member Posts: 92
I have managed to create a "random" number field, simply by
RANDOMIZE;
RndmNumber := RANDOM(12);
Which gives me a number between 1 and 12. How do I give it a minimum? ( I only want 8 - 12) ?
Thanks
RANDOMIZE;
RndmNumber := RANDOM(12);
Which gives me a number between 1 and 12. How do I give it a minimum? ( I only want 8 - 12) ?
Thanks

0
Answers
-
You can't do minimum but ...
RndmNumber := RANDOM(4) + 8 should do nicelyDon't just take my word for it, test it yourself0 -
I completely agree with sunset's approach.
I've found in the past that Navision's random number generator is not as "random" as I would have expected. This could mean that you're loop may end up repeating too many times if there are a lot of random numbers generated that are less then or equal to 7.0 -
Sunset wrote:You can't do minimum but ...
RndmNumber := RANDOM(4) + 8 should do nicely
Excellence in simplicity, I like that one0 -
This way to generate numbers is very similar in all languages. Some languages had just random generator generating numbers between 0 and 1. It means, if you wanted to have numbers from range 10..90 you needed to doI := RANDOM*80+10;
8)0 -
thanks
i did think that the loop may end up looping continually if the random number never went over 7!!
So went for
RANDOM(5) + 7; (so that 8 is given a chance)!0 -
So how can I get this code into a Text field0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions