using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Data
{
public interface IItem
{
public int Id { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Data
{
public class Item : IItem, IComparable<Item>
{
public Item()
{
}
public int Id { get; set; }
public string Name { get; set; }
public override string ToString()
{
return $" Id: {Id}, Name: {Name} ";
}
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
return false;
Item other = (Item)obj;
return Id == other.Id && string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase);
}
public override int GetHashCode()
{
return Id.GetHashCode() ^ (Name ?? "").GetHashCode(StringComparison.OrdinalIgnoreCase);
}
public int CompareTo(Item? other)
{
return Id.CompareTo(other.Id);
}
}
}
using Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RandomData
{
public static class RandomDataFilling
{
public static async Task< List<Item>> GenerateItems(int minValue, int maxValue, int loop)
{
List<Item> items = new List<Item>();
List<int> list = new List<int>();
Random random = new Random();
for (int i = 0; i < loop; i++)
{
int randomNumber = random.Next(minValue, maxValue);
list.Add(randomNumber);
}
foreach (var item in list)
{
if (list.Contains(item))
{
items.Add(new Item { Id = item, Name = $"Name_{Guid.NewGuid()}" });
}
}
return items;
}
public static async Task<int> GenerateRandomId(int minValue, int maxValue)
{
Random random = new Random();
int randomNumber = random.Next(minValue, maxValue);
return randomNumber;
}
}
}