From 3986206de89f7094ba1300e72a7a46916bae7ff4 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 27 Jun 2013 17:19:09 -0400 Subject: Added a function. --- core/network.c | 14 ++++++++++++++ core/network.h | 3 +++ 2 files changed, 17 insertions(+) (limited to 'core') diff --git a/core/network.c b/core/network.c index 81da3f1b..a20b02f6 100644 --- a/core/network.c +++ b/core/network.c @@ -40,6 +40,16 @@ uint64_t current_time() } +int random_int() +{ + #ifdef WIN32 + //TODO replace rand with a more random windows function + return rand(); + #else + return random(); + #endif +} + //our UDP socket, a global variable. static int sock; @@ -87,7 +97,11 @@ int init_networking(IP ip ,uint16_t port) { return -1; } + + #else + srandom((uint32_t)current_time()); #endif + srand((uint32_t)current_time()); //initialize our socket sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); diff --git a/core/network.h b/core/network.h index 24f7281d..da92837d 100644 --- a/core/network.h +++ b/core/network.h @@ -79,6 +79,9 @@ typedef struct //returns current time in milleseconds since the epoch. uint64_t current_time(); +//return a random number +int random_int(); + //Basic network functions: //Function to send packet(data) of length length to ip_port -- cgit v1.2.3