我已经实现了自己tmpnam()
的创建临时文件的功能。我使用以下定义来调整这个:
/* The length of random string. In /tmp/test143276 is 143246 */
#define RND_ROUND 6
/* Used as a minimal bound produced by number generator */
#define RND_MIN 100000
/* Used as a maximum bound produced by number generator */
#define RND_MAX 1000000
如您所见,真正需要的宏是RND_ROUND
,而其他宏是传递给数字生成器的导数。生成公式为:
RND_MIN = 1 and [RND_ROUND-1] zeros
RND_MAX = 1 and [RND_ROUND] zeros
问题:如何创建一些在编译时生成RND_MIN
和RND_MAX
基于的宏?RND_ROUND
例子:
#define RND_ROUND 6
// somehow define those RND_MIN and RND_MAX
...
int32_t random = g_rand_int_range(generator, RND_MIN(RND_ROUND), RND_MAX(RND_ROUND));