Re: [go-nuts] Randomizing contents of a file

2016-09-20 Thread Bakul Shah
Not quite what you asked for but rather than use N goroutines, why not slurp in the whole file in a list ([]string) of lines and then output them in random order? Something like for _, i := range deal(len(lines)) { fmt.Println(lines[i]) } Where you'd write deal(n) to return a list of n numbe

Re: [go-nuts] Randomizing contents of a file

2016-09-20 Thread Marvin Renich
* Marvin Renich [160920 08:26]: > As a general rule of thumb, use a select only when you have more than > one channel send and/or receive that you want to wait for, and only use ^ different > a default case when you have other work that can be done if the channel > operations are all blocked

Re: [go-nuts] Randomizing contents of a file

2016-09-20 Thread Marvin Renich
* Unknown User [160920 06:43]: > Hi All, > > I am trying to print the contents of a file randomizing the lines. > The following code works, but does not exit even after all the lines are > read. > What needs to be done to correct it? Try this package mai

[go-nuts] Randomizing contents of a file

2016-09-20 Thread Dave Cheney
Break breaks out of the select, not the for. Return would work here, or you could use a labled break. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nut

[go-nuts] Randomizing contents of a file

2016-09-20 Thread Unknown User
Hi All, I am trying to print the contents of a file randomizing the lines. The following code works, but does not exit even after all the lines are read. What needs to be done to correct it? package main import( "fmt" "bufio" "os" "math/rand" "time" ) func main() { fil