Basically, I need something like this:
f(a[], b[]) = random element from a[] which is not in b[]
Idea I have is this one:
while true:
e = element_from_uniform(a[])
if e not in b[]: return e
Problem is, I want this function to be fast, since it will be calculating many many times (every frame on multiple objects). I know that since we are choosing from uniform distribution, eventually some element from a[] will pop up that isn't in b[].
Any ideas? Oh, if it helps, a[].length is always 6 and b[] is always some subset of a[] and b.length < a.length.
EDIT:
I want this to be done without allocating any of new memory, only with pointers.
Aucun commentaire:
Enregistrer un commentaire