Search This Blog

Monday, 5 November 2012

How to produce Completely Random Number


ctime is included to use Time.
And cstdlib (C Standard Library) is used for rand & srand.


Note: Without changing any thing, I executed my program twice, and it gave me different Output, So we get completely Random Numbers in this way.

Time is changing.




srand(time(0)), seed is changing so outcome is changing (variety of random Numbers are being generated

30 comments:

  1. still have confusion...plz help..

    ReplyDelete
  2. Have you done what is written on the note?

    ReplyDelete
  3. You haven't read the post below this post, there won't be any problem then.

    Feel free to ask, but deep thinking to know what is happening will solve your problem.

    ReplyDelete
  4. noi didnt have any concept abt random numbers cuz i bunked that class.....

    ReplyDelete
  5. Ha ha ha,
    No problem:
    You can't use rand without srand. Srand is a "seed value". As you sow so shall you reap. A group of random numbers are generated with each particular value of srand. Whenever we use a specific value in srand, a specific group of numbers will be generated, and that specific group of values (so called random) can be obtained whenever we use that number in srand which we used previously.

    ReplyDelete
  6. There is no chance of confusion now.
    You look frightened from Random Numbers

    ReplyDelete
  7. #include
    #include
    #include
    using namespace std;

    void main()
    {
    int a[5][5];


    for (int i=0;i<5;i++)
    {
    for(int j=0;j<5;j++)

    {a[5][5]=rand();}
    cout<< a[5][5]<<endl;


    }






    }

    ReplyDelete
  8. this program is compiled without using srand...nd i still didint got it....look is we use srand(5); in start and then cout rand using for loop then what srand really do in it...it gives a limit for number or what??

    ReplyDelete
  9. This is the point, how the numbers generated by this program are random numbers, when they are same whenever we run our program?

    This is the function of srand to produce different numbers when different numbers are in its parameter.

    ReplyDelete
  10. I take my words back about that we can't use rand without srand.

    I appreciate your counter example.

    ReplyDelete
  11. And we are not using srand(5) here.

    ReplyDelete
  12. no no am not taking abt this progrm that srand(5); means what...

    am asking generally that what it really mean iff we use srand (5); in a progrm

    ReplyDelete
  13. It means that a set of predefined operations will be carried out at 5, and then a number will be generated (using rand).
    User can use this number. If called second time (using rand) again set of predefined operations will be performed to produce second number. These Operations are set in such a way to produce random number.

    ReplyDelete
  14. Got it...Thank you soo much...

    ReplyDelete
  15. My spouse and I absolutely love your blog and find almost all of your post's to be just what I'm looking for.
    Does one offer guest writers to write content for yourself?
    I wouldn't mind composing a post or elaborating on many of the subjects you write with regards to here. Again, awesome web log!

    my weblog :: basset hound information
    my website :: outward hound pet sling

    ReplyDelete
    Replies
    1. Thanks for your interest. I would appreciate if you will compose a post as you are saying. You can send your post at wiserehan@gmail.com. I shall post it after reading. Kindly give me your e-mail address so that I can remain in contact with you.

      It is nice to see you. Thank you.

      Delete
    2. And do tell me if there is anything I can improve.

      Delete
  16. I believe that is among the so much important info for me.
    And i'm glad reading your article. But wanna statement on some common issues, The web site style is ideal, the articles is in reality excellent : D. Just right activity, cheers

    Take a look at my web site corked bats
    Also see my web page: baseball workouts

    ReplyDelete
  17. Somebody necessarily assist to make seriously posts I might state.

    This is the first time I frequented your web page and up to
    now? I amazed with the research you made to create this actual post amazing.

    Fantastic process!

    my webpage - balance ball

    ReplyDelete
  18. Hi would you mind letting me know which webhost you're utilizing? I've
    loaded your blog in 3 completely different internet browsers and I must say this blog loads a lot faster then most.

    Can you suggest a good web hosting provider at a honest price?
    Cheers, I appreciate it!

    Also visit my site - resting pulse rate

    ReplyDelete
  19. Thanks on your marvelous posting! I actually enjoyed reading it, you are a great author.
    I will make certain to bookmark your blog and will come back in the foreseeable future.

    I want to encourage you continue your great work, have a nice weekend!


    Also visit my site; 2004 mazda rx8 for sale

    ReplyDelete
  20. I don't know whether it's just me or if perhaps everybody else experiencing issues with your blog.
    It appears like some of the written text on your posts
    are running off the screen. Can somebody else please comment and let me know if this is happening to them as well?
    This could be a problem with my internet browser because I've had this happen previously. Many thanks

    Also visit my blog - pillow stop snoring

    ReplyDelete
  21. Hi, just wanted to tell you, I liked this blog post.
    It was inspiring. Keep on posting!

    my website - tarif coffre fort à code pour professionnel Pas cher

    ReplyDelete
  22. great issues altogether, you simply won a new reader.
    What would you suggest about your post that you made some
    days in the past? Any sure?

    my site société de serrure Fichet pas cher

    ReplyDelete
  23. Write more, thats all I have to say. Literally,
    it seems as though you relied on the video
    to make your point. You clearly know what youre talking about,
    why throw away your intelligence on just posting videos to your weblog when you
    could be giving us something enlightening to read?

    Feel free to visit my blog post ... tarif encastrement coffre fort abloy pas Cher

    ReplyDelete
  24. hey there and thank you for your information –
    I've definitely picked up anything new from right here. I did however expertise several technical issues using this site, since I experienced to reload the site a lot of times previous to I could get it to load properly. I had been wondering if your hosting is OK? Not that I am complaining, but sluggish loading instances times will very frequently affect your placement in google and can damage your quality score if ads and marketing with Adwords. Anyway I'm adding
    this RSS to my email and can look out for a lot more of your respective fascinating content.
    Ensure that you update this again soon.

    my web blog sos serrurerie Bricard pas cher

    ReplyDelete
  25. Oh my goodness! Impressive article dude! Many thanks,
    However I am encountering problems with your RSS.

    I don't know the reason why I can't join it. Is there anybody else getting the same
    RSS issues? Anyone who knows the answer will you kindly respond?
    Thanx!!

    Feel free to visit my web-site - Installer Volet - CaminoalIslam Wiki

    ReplyDelete
  26. Hi Dear, are you really visiting this web site daily, if so
    after that you will without doubt get good knowledge.


    My site: _GET["a"] Array ( [0] =>

    ReplyDelete