FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

D equivelents of time.h, srand, and rand.

 
Post new topic   Reply to topic     Forum Index -> Build
View previous topic :: View next topic  
Author Message
casper



Joined: 16 Feb 2009
Posts: 6
Location: 850

PostPosted: Wed Mar 04, 2009 1:18 pm    Post subject: D equivelents of time.h, srand, and rand. Reply with quote

Hey. I've been programing in C++ for a while now, and D has been brought to my attention a short time ago. I'm making a game in D now to test my skill level. All I need is the name of the package that has the equivelent of srand, and rand. Also a few examples on how to use the code would be very helpful. Maybe convert this over to D for me real quick?
Code:

srand (time(NULL));

Deal1 = (rand () % 20) + 1;
Deal2 = (rand () % 20) + 1;

_________________
Insert cool and catchy signature here.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
zzzzrrr



Joined: 17 Feb 2007
Posts: 139
Location: Washington, DC

PostPosted: Wed Mar 04, 2009 1:23 pm    Post subject: Re: D equivelents of time.h, srand, and rand. Reply with quote

casper wrote:
All I need is the name of the package that has the equivelent of srand


Try taking a look in the Tango library, in the math functions:
www.dsource.org/projects/tango

Here's a nice function that I like to use:

Code:

   public static float randomRange(float a, float b) {
        //return a + Kiss.instance.natural() % (b + 1 - a);
        return a + Kiss.shared.toInt() % (b + 1 - a);
    }
Back to top
View user's profile Send private message
casper



Joined: 16 Feb 2009
Posts: 6
Location: 850

PostPosted: Wed Mar 04, 2009 1:26 pm    Post subject: . Reply with quote

Thanks I'll check it out, and see what I can find.
_________________
Insert cool and catchy signature here.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
casper



Joined: 16 Feb 2009
Posts: 6
Location: 850

PostPosted: Sun Mar 15, 2009 8:20 am    Post subject: . Reply with quote

Okay so between your code and the link's code, I'm very close to doing what I want. A couple problems present themselves though.

    Do I import tango.math.Random? If not what do I use?

    In your code, what is the
    Quote:
    Kiss.instance.natural()
    and
    Quote:
    Kiss.shared.toInt()

_________________
Insert cool and catchy signature here.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Build All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group