<commit_before>﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace FlatRedBall.Utilities
{
    public class GameRandom : Random
    {
        /// <summary>
        /// Returns a random element in a list.
        /// </summary>
        /// <typeparam name="T">The list type.</typeparam>
        /// <param name="list">The list to return an element from.</param>
        /// <returns>A random element, obtained by using the Next method to obtain a random index.</returns>
        public T In<T>(IList<T> list) => list[Next(list.Count)];

        /// <summary>
        /// Returns a random number within the specified range (inclusive).
        /// </summary>
        /// <param name="lowerBound">The inclusive lower bound.</param>
        /// <param name="upperBound">The inclusive upper bound</param>
        /// <returns>The random float between the bounds.</returns>
        public float Between(float lowerBound, float upperBound) => lowerBound + (float)NextDouble() * (upperBound - lowerBound);

        /// <summary>
        /// Returns a random angle in radians (between 0 and 2*Pi).
        /// </summary>
        /// <returns>A random angle in radians.</returns>
        public float AngleRadians() => (float)NextDouble() * MathHelper.TwoPi;

        /// <summary>
        /// Returns a random angle in degrees (0 to 360)
        /// </summary>
        /// <returns>A random angle in degrees.</returns>
        public float AngleDegrees() => (float)NextDouble() * 360;


        /// <summary>
        /// Returns a 2-dimensional vector in a random direction with length within
        /// the specified range.
        /// </summary>
        /// <param name="minLength">The inclusive lower bound of the length.</param>
        /// <param name="maxLength">The inclusive upper bound of the length.</param>
        /// <returns>The resulting 2-dimensional vector.</returns>
        public Vector2 RadialVector2(float minLength, float maxLength)
        {
            var angle = AngleRadians();
            var length = Between(minLength, maxLength);

            return new Vector2(
                (float)System.Math.Cos((double)angle * length), 
                (float)System.Math.Sin((double)angle * length));
        }

    }
}<commit_msg>[Engine] Fixed bug in GameRandom.RadialVector2 where it was always a unit vector.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace FlatRedBall.Utilities
{
    public class GameRandom : Random
    {
        /// <summary>
        /// Returns a random element in a list.
        /// </summary>
        /// <typeparam name="T">The list type.</typeparam>
        /// <param name="list">The list to return an element from.</param>
        /// <returns>A random element, obtained by using the Next method to obtain a random index.</returns>
        public T In<T>(IList<T> list) => list[Next(list.Count)];

        /// <summary>
        /// Returns a random number within the specified range (inclusive).
        /// </summary>
        /// <param name="lowerBound">The inclusive lower bound.</param>
        /// <param name="upperBound">The inclusive upper bound</param>
        /// <returns>The random float between the bounds.</returns>
        public float Between(float lowerBound, float upperBound) => lowerBound + (float)NextDouble() * (upperBound - lowerBound);

        /// <summary>
        /// Returns a random angle in radians (between 0 and 2*Pi).
        /// </summary>
        /// <returns>A random angle in radians.</returns>
        public float AngleRadians() => (float)NextDouble() * MathHelper.TwoPi;

        /// <summary>
        /// Returns a random angle in degrees (0 to 360)
        /// </summary>
        /// <returns>A random angle in degrees.</returns>
        public float AngleDegrees() => (float)NextDouble() * 360;


        /// <summary>
        /// Returns a 2-dimensional vector in a random direction with length within
        /// the specified range.
        /// </summary>
        /// <param name="minLength">The inclusive lower bound of the length.</param>
        /// <param name="maxLength">The inclusive upper bound of the length.</param>
        /// <returns>The resulting 2-dimensional vector.</returns>
        public Vector2 RadialVector2(float minLength, float maxLength)
        {
            var angle = AngleRadians();
            var length = Between(minLength, maxLength);

            return new Vector2(
                (float)System.Math.Cos((double)angle) * length, 
                (float)System.Math.Sin((double)angle) * length);
        }

    }
}
{'fraction_non_alphanumeric': 0.13253527148353997, 'fraction_numerical': 0.006199230440359128, 'mean_word_length': 2.2047945205479453, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4667297', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1183, 'n_words': 391}