mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-27 09:58:45 +01:00
replace call to rand() with android_only function that reads two bytes
from /dev/urandom. rand() has been returning pretty crappy numbers resulting in lots of clustering of tiles in trays. Let's see if this is any better.
This commit is contained in:
parent
b4fb57de9c
commit
1653b9f6e9
4 changed files with 23 additions and 4 deletions
|
@ -10,7 +10,7 @@ local_C_INCLUDES+= \
|
||||||
|
|
||||||
local_LDLIBS += -llog
|
local_LDLIBS += -llog
|
||||||
|
|
||||||
# local_DEBUG = -DMEM_DEBUG -DDEBUG -DENABLE_LOGGING
|
local_DEBUG = -DMEM_DEBUG -DDEBUG -DENABLE_LOGGING
|
||||||
local_DEFINES += \
|
local_DEFINES += \
|
||||||
$(local_DEBUG) \
|
$(local_DEBUG) \
|
||||||
-DXWFEATURE_RELAY \
|
-DXWFEATURE_RELAY \
|
||||||
|
@ -18,6 +18,7 @@ local_DEFINES += \
|
||||||
-DXWFEATURE_CHAT \
|
-DXWFEATURE_CHAT \
|
||||||
-DSHOW_PROGRESS \
|
-DSHOW_PROGRESS \
|
||||||
-DKEY_SUPPORT \
|
-DKEY_SUPPORT \
|
||||||
|
-DPLATFORM_ANDROID \
|
||||||
-DXWFEATURE_CROSSHAIRS \
|
-DXWFEATURE_CROSSHAIRS \
|
||||||
-DPOINTER_SUPPORT \
|
-DPOINTER_SUPPORT \
|
||||||
-DSCROLL_DRAG_THRESHHOLD=1 \
|
-DSCROLL_DRAG_THRESHHOLD=1 \
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "andutils.h"
|
#include "andutils.h"
|
||||||
|
|
||||||
#include "comtypes.h"
|
#include "comtypes.h"
|
||||||
|
@ -452,6 +456,17 @@ and_empty_stream( MPFORMAL AndGlobals* globals )
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XP_U16
|
||||||
|
and_rand( void )
|
||||||
|
{
|
||||||
|
XP_U16 num;
|
||||||
|
int fd = open( "/dev/urandom", O_RDONLY );
|
||||||
|
XP_ASSERT( fd >= 0 );
|
||||||
|
(void)read( fd, &num, sizeof(num) );
|
||||||
|
close( fd );
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
/* #ifdef DEBUG */
|
/* #ifdef DEBUG */
|
||||||
/* XP_U32 */
|
/* XP_U32 */
|
||||||
/* andy_rand( const char* caller ) */
|
/* andy_rand( const char* caller ) */
|
||||||
|
|
|
@ -48,7 +48,7 @@ typedef XP_U32 XP_Time;
|
||||||
#define XP_CR "\n"
|
#define XP_CR "\n"
|
||||||
#define XP_LD "%ld"
|
#define XP_LD "%ld"
|
||||||
|
|
||||||
# define XP_RANDOM() rand()
|
#define XP_RANDOM() and_rand()
|
||||||
|
|
||||||
#ifdef MEM_DEBUG
|
#ifdef MEM_DEBUG
|
||||||
# define XP_PLATMALLOC(nbytes) malloc(nbytes)
|
# define XP_PLATMALLOC(nbytes) malloc(nbytes)
|
||||||
|
@ -95,6 +95,8 @@ void and_assert( const char* test, int line, const char* file, const char* func
|
||||||
#define XP_WARNF(...)
|
#define XP_WARNF(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
XP_U16 and_rand(void);
|
||||||
|
|
||||||
XP_U32 and_ntohl(XP_U32 l);
|
XP_U32 and_ntohl(XP_U32 l);
|
||||||
XP_U16 and_ntohs(XP_U16 s);
|
XP_U16 and_ntohs(XP_U16 s);
|
||||||
XP_U32 and_htonl(XP_U32 l);
|
XP_U32 and_htonl(XP_U32 l);
|
||||||
|
@ -114,4 +116,3 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -132,10 +132,12 @@ getRandomTile( PoolContext* pool )
|
||||||
|
|
||||||
#if defined PLATFORM_PALM && ! defined XW_TARGET_PNO
|
#if defined PLATFORM_PALM && ! defined XW_TARGET_PNO
|
||||||
XP_U16 rr = XP_RANDOM();
|
XP_U16 rr = XP_RANDOM();
|
||||||
|
#elif defined PLATFORM_ANDROID
|
||||||
|
XP_U16 rr = XP_RANDOM();
|
||||||
#else
|
#else
|
||||||
XP_U16 rr = (XP_U16)(XP_RANDOM()>>16);
|
XP_U16 rr = (XP_U16)(XP_RANDOM()>>16);
|
||||||
#endif
|
#endif
|
||||||
XP_U16 index = (XP_U16)(rr % pool->numTilesLeft);
|
XP_U16 index = rr % pool->numTilesLeft;
|
||||||
Tile result = getNthPoolTile( pool, index );
|
Tile result = getNthPoolTile( pool, index );
|
||||||
|
|
||||||
--pool->lettersLeft[result];
|
--pool->lettersLeft[result];
|
||||||
|
|
Loading…
Reference in a new issue