code: def test_random_rec_from_candidates():
      algo = basic.Random()
      items = lktu.ml_test.ratings["item"].unique()
      users = lktu.ml_test.ratings["user"].unique()
      user1, user2 = np.random.choice(users, size=2, replace=False)
      algo.fit(lktu.ml_test.ratings)
  
      # recommend from candidates
      candidates = np.random.choice(items, 500, replace=False)
      recs1 = algo.recommend(user1, 100, candidates=candidates)
      recs2 = algo.recommend(user2, 100, candidates=candidates)
      assert len(recs1) == 100
      assert len(recs2) == 100
  
file_path: lkpy/tests/test_util_algos.py
imports: from lenskit.algorithms import basic
  import pandas
  import numpy
  import lenskit.util.test
label_desc: Use image node_id 8 for calling a global function with example usage: test_random_rec_from_candidates() without return types