mibuso.com

Microsoft Business Solutions online community
It is currently Fri May 24, 2013 3:58 am

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Can you get truly random numbers from Dynamics NAV?
PostPosted: Wed May 09, 2012 12:05 am 
Offline

Joined: Thu Oct 14, 2010 2:35 am
Posts: 62
Location: Orem, Utah
Country: United States (us)
I use random numbers for testing a lot, and I'm used to Excel, where you can get a lot of precision from '=RAND()'

It seems like the easiest way to replicate the Excel RAND function in Navision is with this code:
Code: Select all
RANDOMIZE;
x :=  RANDOM(2147483647)/2147483647)
And, then this really isn't a true random number, but it's based on an algorithm that wouldn't pass really advanced randomness tests.

Is there something better in Navision than RANDOM? Or, do you know if future versions of Navision will support random numbers that are more random?

_________________
Joseph Dewey
Microsoft Dynamics NAV User


Top
 Profile E-mail  
 
 Post subject: Re: Can you get truly random numbers from Dynamics NAV?
PostPosted: Wed May 09, 2012 8:14 am 
Offline

Joined: Tue Jun 23, 2009 6:51 am
Posts: 47
Hope this helps :D :-

RandomDigit := CREATEGUID;
RandomDigit := DELCHR(RandomDigit,'=','{}-01');
RandomDigit := COPYSTR(RandomDigit,1,10);


Top
 Profile E-mail  
 
 Post subject: Re: Can you get truly random numbers from Dynamics NAV?
PostPosted: Wed May 09, 2012 9:24 am 
Offline
Moderator
MVP Microsoft Dynamics NAV
NAV TechDays 2013 attendee

Joined: Wed Jul 02, 2003 10:13 am
Posts: 7501
Location: Milan
Country: Italy (it)
Well, also GUID is not really random, but it probably is more random than RANDOM.

_________________
Regards,Alain Krikilion
Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title! || Read Forum Rules before making a posting


Top
 Profile  
 
 Post subject: Re: Can you get truly random numbers from Dynamics NAV?
PostPosted: Wed May 09, 2012 10:14 am 
Offline

Joined: Thu Oct 30, 2008 10:38 am
Posts: 987
Location: Earth
Country: Netherlands (nl)
take the last digit of currentdatetime, (the ones after the decimal seperator).
Guaranteed to be random.

_________________
|Pressing F1 is so much faster than opening your browser|
|MCBMSS: 5.0 intro|MCTS:NAV09 839..841|JetReports© Certified Specialist|
|Dynamics Anywhere: Mobile Business Solutions|


Top
 Profile  
 
 Post subject: Re: Can you get truly random numbers from Dynamics NAV?
PostPosted: Wed May 09, 2012 11:54 am 
Offline
Moderator
MVP Microsoft Dynamics NAV
NAV TechDays 2013 attendee

Joined: Wed Jul 02, 2003 10:13 am
Posts: 7501
Location: Milan
Country: Italy (it)
or also with TIME.

I tried this code:

Code: Select all
for i := 1 to 1000000 do begin
  tim := time;
  tim2 := 000000T;
  int := (tim - tim2) MOD 1000;

  tmpInteger.Number := int;
  if tmpInteger.insert then ;
end;

message('%1',tmpInteger.count);

With this I wanted to see if the last 2 digits (the milliseconds) can have all values and the count is always close to 1000. So this is not a bad system.

_________________
Regards,Alain Krikilion
Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title! || Read Forum Rules before making a posting


Top
 Profile  
 
 Post subject: Re: Can you get truly random numbers from Dynamics NAV?
PostPosted: Thu May 10, 2012 8:11 pm 
Offline

Joined: Thu Oct 14, 2010 2:35 am
Posts: 62
Location: Orem, Utah
Country: United States (us)
Using the last digit of the thousands in TIME (the milliseconds count) to generate a random number is definitely a unique approach. The biggest problem with this, though, is that Navision does many calculations per millisecond, so even though this would probably generate a random enough number between 0 and 9, then it kind of falls apart when you need something outside of the 0 to 9 range, or if you need multiple numbers.

But, I did make a working prototype that gives pretty random numbers. It's pretty slow, and I would guess that it wouldn't pass too many heavy-duty randomness tests. Also, about half of the time this gives a number with far fewer decimal places than the max. I don't understand why my code does that.

But the numbers it generates do look random.
Code: Select all
FOR j := 1 TO 10 DO BEGIN
  rand_string := '0.';
  FOR i := 1 TO 20 DO BEGIN
    rand_string := rand_string + COPYSTR(FORMAT(TIME,0,'<Thousands>'),3,1);
    SLEEP(1); //try removing this to see what happens
  END;
  EVALUATE(rand_dec, rand_string);
  MESSAGE('%1',rand_dec);
END;
Thanks for your ideas!

_________________
Joseph Dewey
Microsoft Dynamics NAV User


Top
 Profile E-mail  
 
 Post subject: Re: Can you get truly random numbers from Dynamics NAV?
PostPosted: Thu May 10, 2012 9:19 pm 
Offline

Joined: Thu Nov 27, 2003 2:49 pm
Posts: 1142
Location: Athens
Country: Greece (gr)
Were do you need to use such a generator?

I guess you could use some dll file that does only than, or even use Excel automation to generate a random number...


Top
 Profile E-mail  
 
 Post subject: Re: Can you get truly random numbers from Dynamics NAV?
PostPosted: Fri May 11, 2012 12:37 am 
Offline

Joined: Thu Oct 14, 2010 2:35 am
Posts: 62
Location: Orem, Utah
Country: United States (us)
Here's my code for using the CREATEGUID to get a random number between 0 and 1.
Code: Select all
FOR j := 1 TO 10 DO BEGIN
  rand_string := '0.';
  WHILE STRLEN(rand_string) < 20 DO
    rand_string := rand_string + DELCHR(CREATEGUID,'=','{}-ABCDEF');
  EVALUATE(rand_dec, rand_string);
  MESSAGE('%1',rand_dec);
END;
I think this is going to be the best method, if I want a true random number, but I think I'll probably mostly just use Navision's RANDOM function. It did pass a few randomness tests that I threw at it.

I use random numbers for testing, mostly. But random numbers are very helpful in a lot of situations. How would I learn how to hook Navision up to a DLL or Excel's automation?

_________________
Joseph Dewey
Microsoft Dynamics NAV User


Top
 Profile E-mail  
 
 Post subject: Re: Can you get truly random numbers from Dynamics NAV?
PostPosted: Fri May 11, 2012 12:49 am 
Offline

Joined: Thu Nov 27, 2003 2:49 pm
Posts: 1142
Location: Athens
Country: Greece (gr)
It depends on the version you are using.

You can look at the Excel Buffer Table to see how to Interact with excel. Otherwise you could create a .NET dll or COM interface depending on the version.


Top
 Profile E-mail  
 
 Post subject: Re: Can you get truly random numbers from Dynamics NAV?
PostPosted: Fri May 11, 2012 9:57 am 
Offline
Moderator
MVP Microsoft Dynamics NAV
NAV TechDays 2013 attendee

Joined: Wed Jul 02, 2003 10:13 am
Posts: 7501
Location: Milan
Country: Italy (it)
kapamarou wrote:
You can look at the Excel Buffer Table to see how to Interact with excel. Otherwise you could create a .NET dll or COM interface depending on the version.

I would advice against it because:
-you need Excel installed (and probably it must be the correct version)
-It is probably slower than RANDOM because you have to connect to .NET or COM.

After all, why do you need a random no. in NAV. Only to do some tests and for that the C/AL RANDOM is good enough.
If you need random numbers in a scientific way, you
1) need some black box (don't remember the name) that generates really random numbers using quantum fluctuations (some companies have created such a thing)
2) you're really using the wrong language/development environment for that.

_________________
Regards,Alain Krikilion
Use the SEARCH,Luke! || No PM,please use the forum. || May the <SOLVED>-attribute be in your title! || Read Forum Rules before making a posting


Top
 Profile  
 
 Post subject: Re: Can you get truly random numbers from Dynamics NAV?
PostPosted: Fri May 11, 2012 10:01 am 
Offline

Joined: Thu Oct 30, 2008 10:38 am
Posts: 987
Location: Earth
Country: Netherlands (nl)
All in all, I think the topic is answered.
However, I am very curious in what business process a random number is needed.
Is it like a random discount? If you're lucky you'll receive a 100% discount?

_________________
|Pressing F1 is so much faster than opening your browser|
|MCBMSS: 5.0 intro|MCTS:NAV09 839..841|JetReports© Certified Specialist|
|Dynamics Anywhere: Mobile Business Solutions|


Top
 Profile  
 
 Post subject: Re: Can you get truly random numbers from Dynamics NAV?
PostPosted: Fri May 11, 2012 10:02 am 
Offline
Site Admin
MVP Microsoft Dynamics NAV
NAV TechDays 2013 attendee

Joined: Sun Nov 07, 1999 8:01 am
Posts: 3294
Location: Wilrijk
Country: Belgium (be)
If you want to delve into the science of randomness, then look at this site: http://www.random.org/randomness/

_________________
No support using PM or e-mail - Please use this forum.
Search is your friend || Mark your Topic as SOLVED (= green checkmark) when your question is answered || Read the Forum Rules before making a posting

»»» Mark your calendar: NAV TechDays 2013 - 7 & 8 November 2013 ««« Visit the conference website: www.navtechdays.com


Top
 Profile  
 
 Post subject: Re: Can you get truly random numbers from Dynamics NAV?
PostPosted: Fri May 11, 2012 12:03 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Tue Aug 14, 2001 7:01 am
Posts: 5315
Location: Prague
Country: Czech Republic (cz)
Schrodinger's cat is long dead anyway, so why does it matter. :mrgreen:

Get a dog instead. 8)

_________________
David Singleton
Dynamics NAV Freelancer
Dynamics Book
Go-Live International


Top
 Profile E-mail WWW  
 
 Post subject: Re: Can you get truly random numbers from Dynamics NAV?
PostPosted: Fri May 11, 2012 1:46 pm 
Offline

Joined: Thu Oct 30, 2008 10:38 am
Posts: 987
Location: Earth
Country: Netherlands (nl)
David Singleton wrote:
Schrodinger's cat is long dead anyway, so why does it matter. :mrgreen:

David, you can't state that as a fact if you havn't looked under the box :mrgreen:
(And how is this ontopic? I seem to have missed the link between Shrodingers cat and randomness)

_________________
|Pressing F1 is so much faster than opening your browser|
|MCBMSS: 5.0 intro|MCTS:NAV09 839..841|JetReports© Certified Specialist|
|Dynamics Anywhere: Mobile Business Solutions|


Last edited by Sog on Fri May 11, 2012 3:38 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Can you get truly random numbers from Dynamics NAV?
PostPosted: Fri May 11, 2012 2:36 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Tue Aug 14, 2001 7:01 am
Posts: 5315
Location: Prague
Country: Czech Republic (cz)
But if I open the box then the randomness is gone. My gut feeling is that after all these decades trapped in the box that the kitten has by now starved or suffocated :cry:

_________________
David Singleton
Dynamics NAV Freelancer
Dynamics Book
Go-Live International


Top
 Profile E-mail WWW  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: