3 ms·
The programmer should have traveled in time to read this: http://msdn.microsoft.com/en-us/library/ms233801.aspx http://msdn.microsoft.com/en-us/library/ms233801
by return0 13y ago
The programmer should have traveled in time to read this: http://msdn.microsoft.com/en-us/library/ms233801.aspx http://msdn.microsoft.com/en-us/library/ms233801.aspx
- ColinWright 13y agoWhy? They are getting the indexing right. What's wrong is generating a random number from 1 to 16 inclusive. They use RND(1) to generate a random float from 0 to 1, including 0, not including 1. They multiply by 15 (that's the mistake) to get a random float from 0 to 15, not including 15. They use INT to round down to get an INT from 0 to 14 inclusive, then add 1. That gives them an INT from 1 to 15 (inclusive) to access the list of digits. The mistake is they want an INT from 1 to 16, so they should have multiplied by 16. Your link is to a page that talks about the difference between MID, which indexes from 1, and substring, which indexes from 0. Indexing from 1 is not the error, so I don't see why your link is relevant.