jbskaggs ha scritto:
It is Gambas related! Where else are noobs like me going to learn this?
Please continue as you are both teaching me Maestros! To stop now would be
like taking candy from a baby just after the wrapper was opened.
Thanks for your appreciation words. What Dominique
Dominique SIMONART ha scritto:
Doriano Blengino a écrit :
jbskaggs ha scritto:
FOR i = 0 TO ListView1.count - 1 STEP 1
myArray[i] = i
NEXT
FOR i = ListView1.count - 1 TO 0 STEP -1
a = Int(Rnd(i + 1))
SWAP myArray[i], myArray[a]
PRINT i, a
NEXT
Hi Doriano,
I agree to everything you wrote.
I thought the same about what you wrote! :)
... Then, recalling to my mind
the way a person shuffles cards by hand, I tried to
express another
algorithm, which in a certain way lets you to adjust the
randomness: a
person can shuffle very
It is Gambas related! Where else are noobs like me going to learn this?
Please continue as you are both teaching me Maestros! To stop now would be
like taking candy from a baby just after the wrapper was opened.
JB SKaggs
Simonart Dominique wrote:
Hi Doriano,
I agree to everything
Hi yourself! Here is the problem in the code:
FOR i = 0 TO ListView1.Count - 1 ' write items in listview2
TRY PRINT myArray[i]
listview1.MoveTo(myArray[i])
TRY c = listview1.Item.Key
TRY PRINT myArray[i], listview1.item.key , c, counter i: , i, total
count: , listview1.Count
TRY
jbskaggs ha scritto:
FOR i = 0 TO ListView1.count - 1 STEP 1
myArray[i] = i
NEXT
FOR i = ListView1.count - 1 TO 0 STEP -1
a = Int(Rnd(i + 1))
SWAP myArray[i], myArray[a]
PRINT i, a
NEXT
Apart from the problem of missing records, there could be also a
randomness problem in
This works much better at getting a more shuffled list!
Thanks
Doriano Blengino wrote:
jbskaggs ha scritto:
FOR i = 0 TO ListView1.count - 1 STEP 1
myArray[i] = i
NEXT
FOR i = ListView1.count - 1 TO 0 STEP -1
a = Int(Rnd(i + 1))
SWAP myArray[i], myArray[a]
PRINT i, a
NEXT
You were correct! There was a extra comma in the data file that was breaking
the loop!
BTW to you an everyone else if you celebrate it, Happy Easter! If not ignore
me. ;)
JB SKaggs
Simonart Dominique wrote:
Hi again :)
May be you did not see the last sentence of my answer wich
is
--
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
Doriano Blengino a écrit :
jbskaggs ha scritto:
FOR i = 0 TO ListView1.count - 1 STEP 1
myArray[i] = i
NEXT
FOR i = ListView1.count - 1 TO 0 STEP -1
a = Int(Rnd(i + 1))
SWAP myArray[i], myArray[a]
PRINT i, a
NEXT
Apart from the problem of missing records, there
Okay I thought this was worked out but its still not working- I always end up
losing the last two list items.
Here is the console output from my print statements:
This first list is printing i, a from this command SWAP myArray[i],
myArray[a]
21 21
20 13
19 0
18 13
17 11
Hi,
jbskaggs a écrit :
Okay I thought this was worked out but its still not working- I always end up
losing the last two list items.
Here is the console output from my print statements:
This first list is printing i, a from this command SWAP myArray[i],
myArray[a]
21 21
20 13
Hi!
I can't reproduce your problem.
Randomize with seed 12345, I got;
From 0 to 9: 4 0 7 9 5 1 2 6 3 8
From 9 to 0: 4 2 7 8 3 0 6 9 1 5
Both correct.
So maybe there is a bug in SWAP command with Gambas version... what
are you using?
With Gambas 2.10 it is working.
Jussi
P.S. Code I used to
Hi Jussi,
NO, there is no bug, it's my mistake!!
I listed the myArray values just after the SWAP instruction.
But, as you can see it in a preceeding answer to jbskaggs,
this is a bad idea because in the forward FOR NEXT loop
case, these values could change any time. You don't make
this error
When I ran the code it ran fine- why is it important to have it count
backwards in the random swap?
ie for i =199 to 0 step -1 instead of for i=0 to 199 step 1?
JB SKaggs
Simonart Dominique wrote:
Hi,
Hmm, did you run exactly this code? If so, there is
something wrong with the second
Hi,
jbskaggs a écrit :
Okay,
But why does it do that? I don't see why the direction should matter what
am I missing ? Becuase maybe this is something that has plagued me and
caused me headaches for a while.
JB Skaggs
You're right! Thanks!
My mistake is that I listed the myArray
I came up with a way to random sort listview. (Iuse this for random
shuffling card slots on games) But it isnt efficient some pointers if you
dont mind?
I use two listviews one to sort from and one to sort to:
I first copy all the listitems from list 1 to list 2 EXCEPT the key for
listview2
jbskaggs a écrit :
I came up with a way to random sort listview. (Iuse this for random
shuffling card slots on games) But it isnt efficient some pointers if you
dont mind?
I use two listviews one to sort from and one to sort to:
I first copy all the listitems from list 1 to list 2
Simonart Dominique a écrit :
jbskaggs a écrit :
I came up with a way to random sort listview. (Iuse this for random
shuffling card slots on games) But it isnt efficient some pointers if you
dont mind?
I use two listviews one to sort from and one to sort to:
I first copy all the listitems
using your suggestions and the swap command vs manual swapping this is my
code:
public b as string 'optional string used to hold the array data for file or
split later
PUBLIC SUB button4_click() ' initialize array
DIM myArray AS Integer[200]
DIM a AS Integer
DIM i AS Integer
FOR i = 0 TO 199
20 matches
Mail list logo