How Many Different Random Numbers?

  • I got it "right" by eliminating 0 and 20, but the answer is incorrect! When I tested the query, I got 5 values in master and I got different numbers for each database.

    /Hรฅkan Winther
    MCITP:Database Developer 2008
    MCTS: SQL Server 2008, Implementation and Maintenance
    MCSE: Data Platform

  • Eirikur Eiriksson (9/30/2014)


    Thank you for the question Amit.

    Given options of 0,2 and 20 with the set's cardinality of 20 makes this kind of obvious; the granularity of syscolumns is {object,column}, one can rule out 0 as the query will return values, one can also rule out twenty as most objects have more than one column which leaves 2 as the only applicable answer.

    ๐Ÿ˜Ž

    2 is not a correct answer as it will depend on the database. I also eliminated 0 and 20 to get my points, but the answer is still wrong.

    /Hรฅkan Winther
    MCITP:Database Developer 2008
    MCTS: SQL Server 2008, Implementation and Maintenance
    MCSE: Data Platform

  • Same for me - the result is database-dependent, so no answer is correct. Are the questions verified before posting ๐Ÿ˜‰ ?

  • This was removed by the editor as SPAM

  • At least following the recent spate of RAND() questions I found it quicker to spot that the question had gone wrong. I'm beginning to feel I finally know RAND.

  • The mistake in the question was overlooking the fact that sys.syscolumns will have different contents in different databases.

    But more than that, you couldn't guarantee the statement would return the same results in the same database: without an ORDER BY clause in the SELECT statement the TOP 20 clause could return any 20 rows.

  • hakan.winther (9/30/2014)


    Eirikur Eiriksson (9/30/2014)


    Thank you for the question Amit.

    Given options of 0,2 and 20 with the set's cardinality of 20 makes this kind of obvious; the granularity of syscolumns is {object,column}, one can rule out 0 as the query will return values, one can also rule out twenty as most objects have more than one column which leaves 2 as the only applicable answer.

    ๐Ÿ˜Ž

    2 is not a correct answer as it will depend on the database. I also eliminated 0 and 20 to get my points, but the answer is still wrong.

    Knowing that id is not the primary key column of syscolumns and no specific database was designated for the execution of the code, the answer 2 (two) is the only reasonable answer.

    ๐Ÿ˜Ž

  • Stewart "Arturius" Campbell (9/30/2014)


    The answer, however, should have been "It depends"

    +1 to that. I find the interesting part is that a function that's supposed to return "random numbers" returns the same numbers for one of the posters as the ones I got on my system. On the surface, it appears wrong, but if the same seeds are used, it returns the same quantities of the same numbers. It really is nothing more than a function that's consistent, but not always.

    I don't mean to spark a mathematical debate here, but what is truly random anyway? ๐Ÿ˜‰

  • I executed on SQL 2008, SQL 2008R2 and SQL 2012 - I got 6 different random numbers in all 3 test environments. I then started running the query against different databases and received 2 different numbers. Not a good question.

  • Agree with many posts here. Interesting idea, but not correct implementation of the question and options.

    This is my result (SQL 2012, master database) 6 DIFFERENT results:

    (No column name)

    0.713591993212924

    0.713591993212924

    0.713591993212924

    0.713647892126698

    0.713647892126698

    0.713647892126698

    0.713647892126698

    0.713722424011731

    0.713722424011731

    0.713722424011731

    0.713722424011731

    0.713722424011731

    0.713722424011731

    0.713722424011731

    0.713852854810538

    0.713871487781797

    0.713871487781797

    0.713908753724313

    0.713908753724313

    0.713908753724313

    I believe that the question should be corrected.

  • I also got 3, 5 or 6 distinct values depending on the database.

  • I got it right but it's true that you can't really know how many different distinct values you will generate unless you know for certain the values that the Rank function will return.

    Definitely the question and answers could have been better presented.

    Regardless, I thank the author and encourage him to keep posting questions.

    ---------------
    Mel. ๐Ÿ˜Ž

  • andrew.ing (9/30/2014)


    The mistake in the question was overlooking the fact that sys.syscolumns will have different contents in different databases.

    But more than that, you couldn't guarantee the statement would return the same results in the same database: without an ORDER BY clause in the SELECT statement the TOP 20 clause could return any 20 rows.

    The ORDER BY as part of the OVER clause guarantees you that.

    ---------------
    Mel. ๐Ÿ˜Ž

  • We have all been drilled that without an order by there is no guarantee of the order of the records. That being said any number from 1 to 20 could conceivably come up.


    Thanks,

    ToddR

  • This was removed by the editor as SPAM

Viewing 15 posts - 16 through 30 (of 60 total)

You must be logged in to reply to this topic. Login to reply