Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,185 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,060 people online right now. Registration is fast and FREE... Join Now!




Random no generator without using windows API in c++

 
Reply to this topicStart new topic

Random no generator without using windows API in c++

kapoorhimanshu_1
5 Sep, 2007 - 02:48 AM
Post #1

New D.I.C Head
*

Joined: 5 Sep, 2007
Posts: 1


My Contributions
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
User is offlineProfile CardPM
+Quote Post

Pontus
RE: Random No Generator Without Using Windows API In C++
5 Sep, 2007 - 03:04 AM
Post #2

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 529



Thanked: 2 times
Dream Kudos: 275
My Contributions
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?
CODE

#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: 5 Sep, 2007 - 03:07 AM
User is offlineProfile CardPM
+Quote Post

Bench
RE: Random No Generator Without Using Windows API In C++
5 Sep, 2007 - 04:07 AM
Post #3

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 617



Thanked: 14 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
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.eternallyconfuzzled.com/arts/jsw_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!)
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Random No Generator Without Using Windows API In C++
5 Sep, 2007 - 04:33 AM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
QUOTE(manhaeve5 @ 5 Sep, 2007 - 07: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?

since rand() is not actually random, many programmers implement other forms of random number generators.
User is offlineProfile CardPM
+Quote Post

Xing
RE: Random No Generator Without Using Windows API In C++
5 Sep, 2007 - 05:05 AM
Post #5

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
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.

This post has been edited by Xing: 5 Sep, 2007 - 05:06 AM
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Random No Generator Without Using Windows API In C++
5 Sep, 2007 - 11:59 AM
Post #6

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,906



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
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.
User is offlineProfile CardPM
+Quote Post

Pontus
RE: Random No Generator Without Using Windows API In C++
5 Sep, 2007 - 12:54 PM
Post #7

Dreaming Coder / Coding Dreamer
Group Icon

Joined: 28 Dec, 2006
Posts: 529



Thanked: 2 times
Dream Kudos: 275
My Contributions
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.
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Random No Generator Without Using Windows API In C++
5 Sep, 2007 - 01:08 PM
Post #8

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
But you can make a better random number generator than rand(). I believe that was the point.
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Random No Generator Without Using Windows API In C++
6 Sep, 2007 - 09:22 AM
Post #9

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,906



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
QUOTE
The only gamingsystem was the snes i believe, taking the noise made by a fan

Wow, I didn't know that.

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 01:12AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month