His roommate for the last month, Frederick Smith, an undergraduate, said the gunman had moved to the United States eight years ago. He described Mr. Dashti as ''kind of nerdy'' and said he had held a series of odd jobs. Mr. Smith also said Mr. Dashti had kept a large collection of weapons locked in a closet.

'Psychotic Episode'

Police officials here said Mr. Dashti had three weapons in the bar - a revolver and two pistols, one of them a fully automatic MAC-10, which is a 9-millimeter assault weapon that fires a clip of 30 rounds at one time. They added that there was no indication that Mr. Dashti's behavior was related to his nationality or the current tensions in the Persian Gulf.

Instead, they described a man in the midst of a ''psychotic episode.'' Capt. Philip Doran said the gunman ranted at the hostages about ''sexual, racial and other kinds of weird stuff.''

Lieut. Jim Polk, field commander for the hostage negotiating team, said Mr. Dashti issued incoherent demands. He insisted that San Francisco's Police Chief, Frank Jordan, make a conciliatory statement about him on a local television broadcast while stripped from the waist down.

At a news conference with Berkeley police officials, the city's Mayor, Loni Hancock, noted that the violence followed killings around the University of Florida at Gainesville and called for strict gun control laws. ''We will not be safe until we make it impossible to get these kinds of guns,'' Mayor Hancock said.