Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2004

Tip: Looking for answers? Try searching our database.

How to generate a random number between 0 and 1

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard - 30 Mar 2004 21:31 GMT
My program needs a random number between 0 and 1 (0, 1). Who can tell me how to do this? Thanks in advance

Richar

richard.dan@263.net
Jochen Kalmbach - 30 Mar 2004 21:48 GMT
=?Utf-8?B?UmljaGFyZA==?= wrote:

> My program needs a random number between 0 and 1 (0, 1). Who can tell
> me how to do this? Thanks in advance.

C: rand
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vclib/html/_CRT_rand.asp

and some small calculation like
double random()
{
 return ((double) rand()) / (double) RAND_MAX;
}

Managed C++:

declare:
static rnd = new System.Random();

and use:
rnd.NextDouble();

See:
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/cpref/html/frlrfsystemrandomclassnextdoubletopic.asp

Signature

Greetings
 Jochen

  Do you need a memory-leak finder ?
  http://www.codeproject.com/tools/leakfinder.asp
 
  Do you need daily reports from your server?
  http://sourceforge.net/projects/srvreport/

neo - 30 Mar 2004 21:51 GMT
#include <stdio.h

float number = rand() / (float) RAND_MAX

I think... didn't tried it :0)
Richard - 31 Mar 2004 02:56 GMT
neo,

Thanks a lot!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.