|
![]() |
|
Thread Tools | Display Modes |
![]() |
#11 | |
Veteran
Join Date: Apr 2007
Posts: 1,936
Donated: $40
![]() |
Quote:
randint0: Generates a random signed long integer X where "0 <= X < M" holds. randint1: Generates a random signed long integer X where "1 <= X <= M" holds. I think these are accurate, no?
__________________
takkaria whispers something about options. -more- |
|
![]() |
![]() |
![]() |
#12 | |
Adept
Join Date: Sep 2015
Posts: 104
![]() |
Quote:
So, I've tried to change macro to Code:
#define randint0(M) ((s32b) Rand_div(M+1)) Angband developers must used it correctly, despite wrong description. Kudos! Last edited by brbrbr; June 21, 2016 at 16:35. |
|
![]() |
![]() |
![]() |
#13 |
Prophet
Join Date: Dec 2009
Posts: 8,942
![]() |
To be clear, a generator described as "0 <= X < M" should mean that M cannot be generated, i.e. M-1 is the maximum possible value. Are you saying that in fact M-2 is the maximum possible value? The "max is M-1" case is in fact desirable when picking a random item out of an array; if you tried to access item M then you would get an array index out of bounds exception (if you were working in a modern language, but in C you'd just get an access violation at best and major memory corruption at worst).
|
![]() |
![]() |
![]() |
#14 |
Vanilla maintainer
Join Date: Apr 2007
Location: Canberra, Australia
Age: 54
Posts: 7,860
Donated: $60
![]() |
Which is precisely what "Generates a random signed long integer X where "0 <= X < M" holds." means.
X < M and X, M integers means the greatest value X can take is M-1. Trust me, I'm a mathematician.
__________________
One for the Dark Lord on his dark throne In the Land of Mordor where the Shadows lie. |
![]() |
![]() |
![]() |
#15 |
Adept
Join Date: Sep 2015
Posts: 104
![]() |
|
![]() |
![]() |
![]() |
#16 | |
Rookie
Join Date: Jul 2013
Location: In the Misty Mountains
Posts: 23
![]() |
Quote:
once you have reached the Implementor level. |
|
![]() |
![]() |
![]() |
#17 | ||
Rookie
Join Date: Jul 2013
Location: In the Misty Mountains
Posts: 23
![]() |
Quote:
Requestfully, [someone] Git the source code, stick in global variables and report the ratio of successful test-branches / function calls. The ratio should be quite, quite low. (I have the source code, but the last time that I played Angband, I started at 6 pm. I had a level 20 character, but I was very sleepy. I looked at the time and wondered why I was so sleepy at only 3 am. Thirty minutes later, I realized that it was 3:30 pm and that I had been playing Angband for 21 1/2 hours. I'm too old for that and don't intend to play Angband again.) While hardly a reference, the one - but not asserted only- person on this exchange http://stackoverflow.com/questions/1...mber-generator who can be trusted is Rob Napier. Java's implementation seems to me to be the most efficient, while I would say that my algorithm is slightly more efficient for the purposes of Angband than the arc4 algorithm. The performance differences between the 3 algorithms would not even be measurable in microseconds. The primary difference between the 3 algorithms is that I know that I was not paid to design my algorithm. Quote:
My motivation for putting my algorithm into the game was so that I could sleep well knowing that tomorrow's prayers and spells would be answered or rejected efficiently and unbiasedly. There is little practical difference between the old fashioned mod % N method versus using an unbiased algorithm. I just couldn't sleep knowing that Angband's RNG was not perfectly unbiased. Last edited by rhutson; August 16, 2016 at 08:58. |
||
![]() |
![]() |
![]() |
#18 | |
Rookie
Join Date: Jul 2013
Location: In the Misty Mountains
Posts: 23
![]() |
And you now know exactly why a simple modulo was inconsistent with my continued existence.
Quote:
Easier for me and as mind food for eager students, read Ben's comments in z-rand.c and then play around with a program that I wrote just today: Code:
#include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <assert.h> uint32_t randit(uint32_t m) { uint32_t n; n = (0x10000000 / m); return n; } int main(int argc, char *argv[]) { uint32_t i; assert(argc == 2); assert((i = atoi(argv[1])) >= 0); assert(i <= 0x10000000); printf("Part size %u\n", randit(i)); } With parameters of unknown value at compile time, mod is still slightly more expensive than div. Last edited by rhutson; August 16, 2016 at 11:19. |
|
![]() |
![]() |
![]() |
#19 |
Veteran
Join Date: Jun 2007
Posts: 1,367
![]() |
|
![]() |
![]() |
![]() |
#20 | |
Rookie
Join Date: Jul 2013
Location: In the Misty Mountains
Posts: 23
![]() |
Quote:
There is a Lurking Humor in last night's posts. I was a couple of hours into a detailed study comparing the efficiencies and estimating the CPU cycles used by the 3 algorithms mentioned along with speed testing code, and then I wisely decided to use Nick's approach of "Trust me. I wrote it."€ As for the efficiency of my algorithm, I was pleased to discover that it is practically as efficient as reference grade library routines. The algorithm is just more obscure since I was dealing with a different core RNG which was known to produce less than pseudorandom sequences in the lower bits. As for the 28 bit limitation, that can now be safely and trivially bumped up to a more classic 31 bit limitation. If it is really an issue, email me, and I'll email you back some diffs. ![]() Last edited by rhutson; August 16, 2016 at 20:11. |
|
![]() |
![]() |
![]() |
Tags |
rng |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Random map generator. | LostTemplar | Development | 0 | May 16, 2013 22:05 |
Limited Iron Man Mode | EpicMan | Vanilla | 3 | December 4, 2010 06:10 |
Random number generation? | Chud | Vanilla | 21 | November 8, 2010 19:00 |
Mechanic idea for a variant...monster generator | Jude | Variants | 44 | November 19, 2008 21:44 |
Angband Variant without random levels? | TJA | Variants | 32 | August 18, 2007 17:47 |