Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, howardR), 472 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How to Program percentage influence #472628
05/08/18 21:39
05/08/18 21:39
Joined: Aug 2005
Posts: 199
houston
S
seneca Offline OP
Member
seneca  Offline OP
Member
S

Joined: Aug 2005
Posts: 199
houston
Just wondering if someone could help me figure out how to program a percentage influence.

I have 5 items that drop randomly. But I would like for one or two items to drop more frequently then some others.

been racking my brain for a couple of weeks and can't seem to write anything that makes sense or works like I want.

as always any help would be greatly appreciated.


a8 commercial
Re: How to Program percentage influence [Re: seneca] #472635
05/09/18 08:51
05/09/18 08:51
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
for a uniform distribution of the members but one or two, encrease the limits of the range:
Code:
#define MEMBER_COUNT  5
#define LOWER_COUNT   2
//#define MIDDLE_COUNT  3 // MEMBER_COUNT - 2
//#define UPPER_COUNT   3
#define TOTAL_COUNT   8 // LOWER_COUNT + MIDDLE_COUNT + UPPER_COUNT

var itemID = clamp(floor(random(TOTAL_COUNT) - LOWER_COUNT), 0, MEMBER_COUNT - 1);



but when you call 'random' from many places in your code, the uniform distribution of random samples in a single place is lost so you need to build your own random sampler in order to mantain their uniformity. Maybe you are facing that.

Here goes the random apply I adapted from somewhere someday:

random_tail.h
Code:
#ifndef _RANDOM_TAIL_H_
#define _RANDOM_TAIL_H_

typedef struct {
	long a;
	long b;
} RANDOM_TAIL;

// Global random tail
void setRandomSeed (long _seed);
double getRandom (double _range);
double getRandom (); // 0<->1 range

// Custom random tail
RANDOM_TAIL *randomTailCreate (long _seed);
void randomTailRemove (RANDOM_TAIL *_rt);
void setRandomSeed (long _seed, RANDOM_TAIL *_rt);
double getRandom (double _range, RANDOM_TAIL *_rt);

#include "random_tail.c"
#endif



random_tail.c
Code:
RANDOM_TAIL randomTailGlobal;

void setRandomSeed (long _seed, RANDOM_TAIL *_rt) {
	if (_seed) {
		_rt->a = _rt->b =	_seed;
	} else {
		_rt->a = _rt->b =	(long)_rt + sys_hours + sys_minutes + sys_seconds + ~total_ticks; // pseudo random seed
		if (_rt->a == 0)
			_rt->a = 1;
	}
}

void randomTailGlobal_startup () {
	setRandomSeed (0, &randomTailGlobal);
}

void setRandomSeed (long _seed) {
	setRandomSeed (_seed, &randomTailGlobal);
}

long getRandomLong (RANDOM_TAIL *_rt) {
	_rt->a = 36969 * (_rt->a & 65535) + (_rt->a >> 16);
	_rt->b = 18000 * (_rt->b & 65535) + (_rt->b >> 16);
	return (_rt->a << 16) + _rt->b;
}

double getRandom (double _range, RANDOM_TAIL *_rt) {
	double _d = getRandomLong ( _rt );
	return ( _range * 0.5 ) + ( _d + 1.0 ) * _range * 2.328306435454494e-10;
}

double getRandom (double _range) {
	return getRandom (_range, &randomTailGlobal);
}

double getRandom () {
	return getRandom (1.0, &randomTailGlobal);
}

RANDOM_TAIL *randomTailCreate (long _seed) {
	RANDOM_TAIL *_rt = sys_malloc (sizeof(RANDOM_TAIL));
	setRandomSeed (_seed, _rt);
	return _rt;
}

void randomTailRemove (RANDOM_TAIL *_rt) {
	sys_free (_rt);
}



Salud!

Re: How to Program percentage influence [Re: txesmi] #472639
05/09/18 10:14
05/09/18 10:14
Joined: Aug 2005
Posts: 199
houston
S
seneca Offline OP
Member
seneca  Offline OP
Member
S

Joined: Aug 2005
Posts: 199
houston
Oh, yeah! I think this will work for me. Great example to base from. Thank you. i was afraid i was gonna have to rewrite half my current code, but now i believe i can write a workaround that will not disrupt most of my code. Thanks again.


a8 commercial
Re: How to Program percentage influence [Re: seneca] #472645
05/09/18 20:27
05/09/18 20:27
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
glad of been helpful laugh


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1