Question: inside `Laravel Blade file` I'm trying to achieve a simple password generator button that inputs generated password in field

Button:

```
<a class="btn btn-xs btn-success" onClick=generatePass()>Generate Me</a>

<script>
    function generatePass() {
        var hashed_random_password = Hash::make(str_random(12));
            $('#password').val(hashed_random_password);
        }

</script>

```

The button works, tested by using `console.log('button clicked');`
But hashing doesn't work, I need to achieve generating a hashed password and inputs it value directly into the `password form field`

Any suggestion how to get that simply in `blade` without invloving the `routes` and `controller` files?

Answer: 
To build on [@Enigmativity's answer](https://stackoverflow.com/a/73797681/1086121), here's a proper benchmark using BenchmarkDotNet:

```
public class Benchmark
{
    private const int N = 1000000;

    [Benchmark]
    public HashSet<int> EnumerableRange() => new HashSet<int>(Enumerable.Range(1, N + 1));

    [Benchmark]
    public HashSet<int> NoPreallocation()
    {
        var result = new HashSet<int>();
        for (int n = 1; n < N + 1; n++)
        {
            result.Add(n);
        }
        return result;
    }

    [Benchmark]
    public HashSet<int> Preallocation()
    {
        var result = new HashSet<int>(N);
        for (int n = 1; n < N + 1; n++)
        {
            result.Add(n);
        }
        return result;
    }
}

public class Program
{
    public static void Main(string[] args)
    {
        BenchmarkRunner.Run(typeof(Program).Assembly);
    }
}

```

With the results:

| Method | Mean | Error | StdDev |
| --- | --- | --- | --- |
| EnumerableRange | 29.17 ms | 0.743 ms | 2.179 ms |
| NoPreallocation | 23.96 ms | 0.471 ms | 0.775 ms |
| Preallocation | 11.68 ms | 0.233 ms | 0.665 ms |

As we can see, using linq is a bit slower than not using linq (as expected), and pre-allocating saves a significant amount of time.
Here's the code to test the three options:

```
var N = 1000000;
var trials = new List<(int method, TimeSpan duration)>();

for (var i = 0; i < 100; i++)
{
    var sw = Stopwatch.StartNew();
    HashSet<int> numbers1 = new HashSet<int>(Enumerable.Range(1, N + 1));
    sw.Stop();
    trials.Add((1, sw.Elapsed));
    sw = Stopwatch.StartNew();
    HashSet<int> numbers2 = new HashSet<int>(N);
    for (int n = 1; n < N + 1; n++)
        numbers2.Add(n);
    sw.Stop();
    trials.Add((2, sw.Elapsed));
    HashSet<int> numbers3 = new HashSet<int>(N);
    foreach (int n in Enumerable.Range(1, N + 1))
        numbers3.Add(n);
    sw.Stop();
    trials.Add((3, sw.Elapsed));
}

for (int j = 1; j <= 3; j++)
    Console.WriteLine(trials.Where(x => x.method == j).Average(x => x.duration.TotalMilliseconds));

```

Typical output is this:

```
31.314788
16.493208
16.493208

```

It is nearly twice as fast to preallocate the capacity of the `HashSet<int>`.

There is no difference between the traditional loop and a LINQ `foreach` option.