code: def random_quaternions(
      n: int,
      dtype: Optional[torch.dtype] = None,
      device: Optional[Device] = None,
  ) -> torch.Tensor:
      """
      Generate random quaternions representing rotations,
      i.e. versors with nonnegative real part.
  
      Args:
          n: Number of quaternions in a batch to return.
          dtype: Type to return.
          device: Desired device of returned tensor. Default:
              uses the current device for the default tensor type.
  
      Returns:
          Quaternions as tensor of shape (N, 4).
      """
      if isinstance(device, str):
          device = torch.device(device)
      o = torch.randn((n, 4), dtype=dtype, device=device)
      s = (o * o).sum(1)
      o = o / _copysign(torch.sqrt(s), o[:, 0])[:, None]
      return o
  
imports: from typing import Optional
  import torch
  import torch.nn.functional
  from ..common.datatypes import Device
label_desc: Use image node_id 10 for calling a global function with example usage: random_quaternions(n, dtype, device) and returns: o