Author Message
casper

Joined: 16 Feb 2009
Posts: 6
Location: 850

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

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.
zzzzrrr

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

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

 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);     }
casper

Joined: 16 Feb 2009
Posts: 6
Location: 850

 Posted: Wed Mar 04, 2009 1:26 pm    Post subject: . Thanks I'll check it out, and see what I can find._________________Insert cool and catchy signature here.
casper

Joined: 16 Feb 2009
Posts: 6
Location: 850

Posted: Sun Mar 15, 2009 8:20 am    Post subject: .

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.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT - 6 Hours Page 1 of 1

 Jump to: Select a forum Projects----------------BindingseclipseDDerelictDFLSinbadDWTDManagerGDB PatchesdAntFWgtkDdoolDDBICode AnalyzerHelixJunoMiniDPyDdluaFreeUniverseElementDescentLuigiYageFlectionedDGDI+MultiArraytango.toolsScrappleSUnitsCMakeDDDwmDefendnonagondallegrodnetFastCGI4DSenderoTransferServerscregexpLDCLylanonofbdtango.scrappleTankWarsbox2d4dStratagemMathematicsOpenMeshDDPlotSimpleXMLDDInstallerDWinKobaltstd2gmp4dMonsterDMocksDREdluceneHouseBotPineappleflowerdkongdnewsHappy MarsUniDNanuDWT-samplesDWT-addonssvgplotVector2DBlazeOdin's EyeAIDDiamondMDEdilSync4OgoNeptuneDangdcollectionsLifeDsharperDReactorSeamzGoodOpenMWIntelliDAkimyrrdinDDevelopmetaDTkdcryptSmallXMLVangodstressp2p-guidruntimeDXBiD3curldapaged2DComicdstatsblipMegaMan X CrossfireDStepTinyTankEnginegaldDeditDDirectX9OpenMeleeLuaLibDynaminEvanescentAutoTool4Dcv2pdbQtDLuaDSemiTwistGoldiedmd-installerCDCDDataDoodleHaxePreDQuantLibDantlrdddmdaaXMLPdrangesxmpplibcl4dSciDcosynedecimalDDebberVisual DOrangePlot2KillDDTMago DebuggerDaxchipmunkDDDBCHaxeD Tutorials----------------Tutorials Language----------------GeneralD Journal ArticlesICFP 2004D Conference 2007 Site----------------SitePotential Projects Inactive----------------MangoAresBuildDSPDig-DugClaytek 3DDDocDeimosConcurrentMinWinCore32L8nightDGrammarArcLibD Server PlatformDCoderWalnutFragBotsunDigDeliriaElephant IDEDCCmolth2dledsswig4ddragon-stldcouplelr-lalrdmdfeDLanChatsdboCORBA SuiteWatcherThe Language MachinedBerBibleDXULIndigodcursesOrionCarbonHeadersCursesTUIsolDDL - D Dynamic LibrariesDBugdLISPTitanMathExtraDamagePoseidonFreudoHydrusVSpluginDTioportDParserosianVelocityreclsNovaANDTDCSwarm'DBCDrulesPlayerTinyXPathUniversalGentooCashewQonkDDSSSSchoonerDoostAikaEBNFserializationtango.mangotango.phobosFuturismtango.posixtango.win32dxmptango.unicodeSableDDRaetangobosWombatHessianDRayFileBaseDazelyamlDBus-DguisteraxFingerpaintGefuegeFruitFactoryDecoratedDStacyhoofbabyBlock'dDDnDKotivoxdmdscript-tangolibcalcdexcelapiDSpecDMDScriptDBenchdweebdmdscript-2ddbg_continuedConPix
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