code: def test_rand_context_working(use_rand_context: bool):
      # Given:
      from sentence_transformers.losses.CachedMultipleNegativesRankingLoss import (
          RandContext,
      )
  
      a = torch.Tensor(1)
      b = torch.Tensor(1)
      random_state = (
          RandContext(a, b) if use_rand_context else nullcontext()
      )
      expected = torch.rand(1000)
      precision = 1e-6
  
      # When:
      with random_state:
          # Then:
          if use_rand_context:
              assert torch.allclose(
                  torch.rand(1000), expected, precision, precision
              )
          else:
              assert not torch.allclose(
                  torch.rand(1000), expected, precision, precision
              )
  
file_path: sentence-transformers/tests/test_cmnrl.py
imports: from contextlib import nullcontext
  from typing import List
  import pytest
  from sentence_transformers import SentenceTransformer, InputExample, losses
  import tqdm
  from transformers import set_seed
  import torch
  from torch.optim import Adam
label_desc: Use image node_id 2 for calling a global function with example usage: test_rand_context_working(use_rand_context) without return types