Creating random array
Okay, I'm extremely tired and I have a question. Let's say I have a 1d array with 26 cells and each cell is filled with a number like so:
PHP Code:
|
Re: Creating random array
Code:
new array[26] |
Re: Creating random array
I hope I understand well what you need. Your array will be filled with random value from 0 to 25. I prefer using another array since it's more fast and easy to do. Another method without using temporary array would be to fill the original array with -1 ( for example ) and each time checking the whole array if the random value is used or not.
Code:
|
Re: Creating random array
Thanks, guys :)
|
Re: Creating random array
Uh.
You know, you are totaly out of topic... :lol: |
Re: Creating random array
I'm a little confused. I was under the impression this was an elementary problem. *shrug*
Here was me thinking for loops were intended to iterate a predetermined (whether constant or variable) number of times. If you do insist on using the wrong keyword, there is no point endlessly increasing and decreasing the loop counter. Code:
172 52 99 63 197 88 109 103 95 54 127 88 68 74 107 138 63 111 123 76 I have a suspicion that the .NET pseudorandom number generator is better in terms of uniform distribution than random_num() and so you might find it takes longer. The way I'd achieve this is to swap random elements around (you can XOR the values if you're partial to that sort of thing). You can either call random_num() twice per swap or use modulus. It's up to you to decide how many iterations is sufficient. I'm sure you don't need me to code an example. You've probably settled for what's above anyway. :) |
Re: Creating random array
This might work well.
Code:
|
Re: Creating random array
Thie code calculates 78 times sizeof(my_array) lol
|
Re: Creating random array
Mine only iterates through my_array twice.
1. Set all slots to 0-25. 2. Swap each slot with a random one. EDIT: connorr, I see what you mean. |
Re: Creating random array
Connorr, can you work out what I'm trying to tell you?
Code:
Code:
amxxdump -d unknown.amxx |
| All times are GMT -4. The time now is 03:08. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.