Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,271 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,438 people online right now. Registration is fast and FREE... Join Now!




uniform number?

 
Reply to this topicStart new topic

uniform number?, get number between -100 and 1

ritamita
2 Dec, 2006 - 03:03 PM
Post #1

New D.I.C Head
*

Joined: 21 Nov, 2006
Posts: 8


My Contributions

I used the instruction as below to get random uniform number.
But I want to get u(-100,1) .
i write 1.0+ (100.0* uniform(s))

is it correct?

----------------------------------------------------------
inline float uniform(long &s){return float(next(s))/m;}
inline long next(long &s){return s = (a * s + c) % m;}
where
const long m = 714025; const long a = 1366; const long c = 150889;
are one of the three sets of linear congruence generators that satisfy all the requirements for reasonable randomness.

User is offlineProfile CardPM
+Quote Post

msg555
RE: Uniform Number?
2 Dec, 2006 - 03:16 PM
Post #2

D.I.C Head
Group Icon

Joined: 4 May, 2006
Posts: 136



Thanked: 2 times
Dream Kudos: 25
My Contributions
Your uniform function generates floating point numbers from in the range [0, 1) right? (including 0 and excluding 1)

To generate a random number between -100 and 1 you would do
1 - 101 * rand()
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 07:51PM

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