Manixat Posted January 10, 2013 Share Posted January 10, 2013 Hello, I am curious as to how is a random number generated? I know I can generate one by using the rand() function, but I can't imagine how one is being generated. Say I need to write my own rand function from scratch, how is it done? Quote Link to comment Share on other sites More sharing options...
Philip Posted January 10, 2013 Share Posted January 10, 2013 Wikipedia's explanation is actually pretty good. In short, it isn't random and uses an algorithm to pick from a pre-defined list. Quote Link to comment Share on other sites More sharing options...
Manixat Posted January 11, 2013 Author Share Posted January 11, 2013 (edited) Well all seems logical, but the one bit that is bothering me is that algorithm. How does it randomly pick a value from the predefined list ?? I know it must be described somewhere there in the article but I hate reading whole articles just to find a tiny bit of information that I need. Now don't misunderstand, I don't want you to read the article for me, just someone to share if is already aware of how that works. Edited January 11, 2013 by Manixat Quote Link to comment Share on other sites More sharing options...
Barand Posted January 11, 2013 Share Posted January 11, 2013 I don't want you to read the article for me, Yes you do. You aren't prepared to do any research yourself. http://mathworld.wolfram.com/RandomNumber.html Quote Link to comment Share on other sites More sharing options...
haku Posted January 11, 2013 Share Posted January 11, 2013 I know it must be described somewhere there in the article but I hate reading whole articles just to find a tiny bit of information that I need. Time to find a new hobby/profession then. The above is essentially a programmers life. I don't think I'm the only one reguarly reading books on programming, and most of any book is redundant, but that's what you do to get the new info. Quote Link to comment Share on other sites More sharing options...
Philip Posted January 11, 2013 Share Posted January 11, 2013 The above is essentially a programmers life. I don't think I'm the only one reguarly reading books on programming, and most of any book is redundant, but that's what you do to get the new info. You should try writing them... ugh... Quote Link to comment Share on other sites More sharing options...
haku Posted January 11, 2013 Share Posted January 11, 2013 I wrote a textbook in my last company - never again. Help on forums is about as much help as I want to give! Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted January 12, 2013 Share Posted January 12, 2013 Well all seems logical, but the one bit that is bothering me is that algorithm. How does it randomly pick a value from the predefined list ?? It isn't random. It's pseudorandom. Given the same seed, you'll always get the same number. PRNGs generate numbers that are difficult to predict without the seed so they look random. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.