Hi All,
I want to generate random no's ,in C++ , without using inbulit function like rand() and all. So i'll be really greatfull , if some one can tell me how to proceed further , algorithms for random no. generation except Mersenne Twister algorith , will really b a great help.
Thnx
Himanshu Kapoor
8 Replies - 8782 Views - Last Post: 06 September 2007 - 10:22 AM
#1
Random no generator without using windows API in c++
Posted 05 September 2007 - 03:48 AM
Replies To: Random no generator without using windows API in c++
#2
Re: Random no generator without using windows API in c++
Posted 05 September 2007 - 04:04 AM
if by no u mean a number then u can use this
EDIT: just noticed in your previous post u dont want rand(), gonna keep the code for other ppl though, and whats wrong with the rand() function?
EDIT: just noticed in your previous post u dont want rand(), gonna keep the code for other ppl though, and whats wrong with the rand() function?
#include <iostream>
#inclide <cstdlib> //for the random number function
#include <ctime> //for the seeding value
using namespace std;
int main()
{
int randnumber;
srand(time(0));// seed your random value
randnumber=rand() %100 +50; //generates a number between 50 and 100
cout<<"Your random number is "<<randnumber<<endl;
cin.get();
return 0;
}
This post has been edited by manhaeve5: 05 September 2007 - 04:07 AM
#3
Re: Random no generator without using windows API in c++
Posted 05 September 2007 - 05:07 AM
This sounds to me more like an algorithm question than a C++ question. Although IMHO, rand() is generally random enough for most things (Maybe not for a slot machine at a casino, but for the average program its good enough).
If you're interested in a better way of using rand (Mainly, a better way of seeding with srand() ) then have a look here
http://www.eternally...w_art_rand.aspx
Otherwise, you could try looking around in algorithm forums, or do a google search for algorithms. C and C++ do not have any other random number facilities.. (Yet!)
If you're interested in a better way of using rand (Mainly, a better way of seeding with srand() ) then have a look here
http://www.eternally...w_art_rand.aspx
Otherwise, you could try looking around in algorithm forums, or do a google search for algorithms. C and C++ do not have any other random number facilities.. (Yet!)
#4
Re: Random no generator without using windows API in c++
Posted 05 September 2007 - 05:33 AM
manhaeve5, on 5 Sep, 2007 - 07:04 AM, said:
if by no u mean a number then u can use this
EDIT: just noticed in your previous post u dont want rand(), gonna keep the code for other ppl though, and whats wrong with the rand() function?
EDIT: just noticed in your previous post u dont want rand(), gonna keep the code for other ppl though, and whats wrong with the rand() function?
since rand() is not actually random, many programmers implement other forms of random number generators.
#5
Re: Random no generator without using windows API in c++
Posted 05 September 2007 - 06:05 AM
The Boost Random Number Library (Boost.Random for short) provides a vast variety of generators and distributions to produce random numbers having useful properties, such as
a ) Uniform Random Number Generator
b ) Non-deterministic Uniform Random Number Generator
c ) Pseudo-Random Number Generator
d ) Random Distribution
e ) Quasi-Random Number Generators etc.
a ) Uniform Random Number Generator
b ) Non-deterministic Uniform Random Number Generator
c ) Pseudo-Random Number Generator
d ) Random Distribution
e ) Quasi-Random Number Generators etc.
This post has been edited by Xing: 05 September 2007 - 06:06 AM
#6
Re: Random no generator without using windows API in c++
Posted 05 September 2007 - 12:59 PM
rand() is not a part of the Windows API.
I have a feeling that your assignment question could be: "Generate A Random Number without using rand(), by using the Windows API"
If that is so, use the GetTickCount() API function and use the result as the seed for any of the algorithms that are mentioned above.
I have a feeling that your assignment question could be: "Generate A Random Number without using rand(), by using the Windows API"
If that is so, use the GetTickCount() API function and use the result as the seed for any of the algorithms that are mentioned above.
#7
Re: Random no generator without using windows API in c++
Posted 05 September 2007 - 01:54 PM
Let me remind u that a computer with no input from natural things, like noise, heat, light. Cant make true random numbers, all of there are pseude-random. The only gamingsystem was the snes i believe, taking the noise made by a fan.
#8
Re: Random no generator without using windows API in c++
Posted 05 September 2007 - 02:08 PM
But you can make a better random number generator than rand(). I believe that was the point.
#9
Re: Random no generator without using windows API in c++
Posted 06 September 2007 - 10:22 AM
Quote
The only gamingsystem was the snes i believe, taking the noise made by a fan
Wow, I didn't know that.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|