playMaker

Author Topic: How do I get a random key from a hashtable, that matches a value[SOLVED]  (Read 1071 times)

SamH

  • Playmaker Newbie
  • *
  • Posts: 41
Let's say I have a hash table (using array maker) that contains 10 people (keys) with a bool value that represents whether or not each one is wearing a hat.

Of all the people (Keys) in the table, I would like to select one that is wearing a hat (Bool is true) at random.

Thanks,
Sam
« Last Edit: April 22, 2020, 02:24:03 AM by jeanfabre »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: How do I get a random key from a hashtable, that matches a value
« Reply #1 on: April 21, 2020, 03:49:01 AM »
Hi.
Best is to create to loop thru the hash table with 'Get Next' and if 'has hat' place in a different hash table or array. then do random on that array/hash table.

make sure to clear that array / hash table before using again.

SamH

  • Playmaker Newbie
  • *
  • Posts: 41
Re: How do I get a random key from a hashtable, that matches a value
« Reply #2 on: April 21, 2020, 02:47:08 PM »
Cool thanks a lot that worked!